SAS Base Certification – Question 4

Question 4: Given the SAS data set WORK.INPUT:

Var1     Var2
------   -------
A        one
A        two
B        three
C        four
A        five

The following SAS program is submitted:

1
2
3
4
5
data WORK.ONE WORK.TWO;
  set WORK.INPUT;
  if Var1='A' then output WORK.ONE;
  output;
run;

How many observations will be in data set WORK.ONE?

Options:

A. 1
B. 2
C. 4
D. 8

*The SAS certification sample problem and answer above are sourced from the official SAS sample questions page. All answer logs, data sets, output, and commentary are provided by this blog.

Correct Answer

Incorrect Answer

Click to see Answer Explanation below

thanks for your support

9 Comments

    Rachel Aug 02, 2015

    Why is the order of work.one not AAA followed by AABCA? In other words if the second output duplicated work.one, why is it not in the same order as work.one in the data step?

    Reply
      Sophia Aug 19, 2015

      Probably because there was no sort and the original data was in this order.

      Reply
      aakash Dec 02, 2016

      because while reading data from the data set, every record is read sequentially.
      The order in which the data is present in the data set, the same order it is going to get parsed and output is being thrown to the data set

      Reply
    steve Nov 16, 2016

    does not seem like a real world problem

    Reply
    shovland Dec 30, 2016

    On this one it helps to read the SAS documentation on the INPUT function.

    Reply
    Noshaba Bakht Feb 18, 2017

    There are 8 observations.
    The first A is due to the fact var1 = ‘A’ then output one.
    the second A is due to the output statement. This is also true for the observation 3 and 4. Then comes B and C from the output statement and the two A’s in the end due to the fact var1 = ‘A’.

    Reply
    kai Apr 28, 2017

    because two statements (if..output..) and (output) are independent. For every observation in work.input, it will be outputted to both work.one and work.two no matter the result of the first statement. (5+3=8) so totally there are 8 observations in work.one.

    Reply
    Daisy May 15, 2018

    I am not what I am missing, but I actually created the work.input dataset and submitted the code in SAS Studio and I got 5 observations. Anyone mind to explain what is going on? Thanks a lot.

    Reply
      GSmith Jul 29, 2018

      Work.One has 8 observations.
      Work.Two has 5 observations.
      The question was about Work.One.

      Reply

Leave a Comment

Please keep in mind that comments are moderated and rel="nofollow" is in use. So, please do not use a spammy keyword or a domain as your name, or it will be deleted. Let us have a personal and meaningful conversation instead.