**Question 6:** The following SAS program is submitted:

1
2
3
4
5
| data class;
set sashelp.class(keep=name age height weight);
drop=age;
newage=age+1;
run; |

data class;
set sashelp.class(keep=name age height weight);
drop=age;
newage=age+1;
run;

The data set **Sashelp.Class** contains 5 variables. What is the result?

**Options:**

a. 0 variables are written because there is a syntax error.
b. 4 variables are written to the data set **Work.class**.
c. 5 variables are written to the data set **Work.class**.
d. 6 variables are written to the data set **Work.class**.

**This blog is not affiliated with SAS or the SAS Institute. All answer logs, data sets, output, and commentary are provided by this blog.*

Click to see Answer Explanation below
**Log: **

21 data class;
22 set sashelp.class(keep=name age height weight);
23 drop=age;
24 newage=age+1;
25 run;
NOTE: There were 19 observations read from the data set SASHELP.CLASS.
NOTE: The data set WORK.CLASS has 19 observations and 6 variables.
NOTE: DATA statement used (Total process time):
real time 0.02 seconds
cpu time 0.01 seconds

** Commentary:**

The dataset option **keep=name age height weight** allows us to write four variables in the output dataset. The statement **drop=age;** and **newage=age+1;** are assignment statements that create two new variables. Thus, the output dataset will have total 6 variables as seen below:

** Data Set(s):**

Wrong, the correct answer is 5 variables. Age won’t appear in output dataset.

shouldnt the answer be 4? the original keep statement says keep 4 variables, and since that is in the set statement, thats all that is kept. nothing can override that, right??

I read where you are not supposed to use a keep and drop statements together. So, in the set statement, you only keep 4 variables. Lets assume that since a keep was used, drop is not a recognized function anymore. Thus, you still only keep 4 variables.

Other idea: Lets assume the drop statement does in fact work like the function is supposed to. Set statement keeps 4 variables, then 1 of those variables are dropped. Thus, only leaving 3 variables.

This is the log from a similar program that I ran to check this. Turns out, the answer is in fact 6 variables and drop is now a variable. Weird but here it is:

1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;

55

56 data class;

57 set orion.discount(keep=product_id start_date end_date unit_sales_price);

58 drop=start_date;

59 newprice=unit_sales_price+1;

60 run;

NOTE: There were 697 observations read from the data set ORION.DISCOUNT.

NOTE: The data set WORK.CLASS has 697 observations and 6 variables.

NOTE: DATA statement used (Total process time):

real time 0.00 seconds

cpu time 0.00 seconds

61

62 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;

74

Drop as statement cannot use ‘=’

Here now it becomes a new variable which copies age in it. Therefore 6 variables