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

does not seem like a real world problem

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

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.