**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; |

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.*

Click to see Answer Explanation below

Log:

68 data WORK.ONE WORK.TWO;

69 set WORK.INPUT;

70 if Var1='A' then output WORK.ONE;

71 output;

72 run;

NOTE: There were 5 observations read from the data set WORK.INPUT.

NOTE: The data set WORK.ONE has 8 observations and 2 variables.

NOTE: The data set WORK.TWO has 5 observations and 2 variables.

NOTE: DATA statement used (Total process time):

real time 0.10 seconds

cpu time 0.01 seconds

**Data set: **

WORK.ONE:

**Data set: **

WORK.TWO:

** Commentary:**

This one is a bit confusing. The key is the second *output* statement on the fourth line of the program. For each record of the input data set, the program *outputs* a row IF (and only IF) *Var1=’A’*. Then, because the second *output* statement is present, it will duplicate the original row from the input data set. Thus, WORK.ONE has 8 observations: 3 for the rows on which *Var1=’A’* and 5 to duplicate the input data set.

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?

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

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

does not seem like a real world problem

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

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’.

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.

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.

Work.One has 8 observations.

Work.Two has 5 observations.

The question was about Work.One.