SAS Base (6)

After a SAS program is submitted, the following is written to the SAS log:

101 data WORK.JANUARY;
102 set WORK.ALLYEAR(keep=product month num_Sold Cost);
103 if Month=’Jan’ then output WORK.JANUARY;
104 Sales=Cost * Num_Sold;
105 keep=Product Sales;
-----
22
ERROR 22-322: Syntax error, expecting one of the following: !,!!, &, *, **, +, -, , <=, <>, =, >, >=, AND, EQ, GE, GT, IN, LE, LT, MAX, MIN, NE, NG, NL,NOTIN, OR, ^=, |, ||, ~=.
106 run;

What changes should be made to the KEEP statement to correct the errors in the LOG?
A. keep=(Product Sales);
B. keep Product, Sales;
C. keep=Product, Sales;
D. keep Product Sales;

Check Answer
Answer: D

注解:KEEP用于指定需要包括在data set中的变量。与之相反的是DROP,用于指定那些不需要的变量。KEEP和DROP既可作为option跟在DATA statement或者SET statement后面,也可以作为独立的statement出现。当作为option时,需要写在括号内,并跟上一个等号,比如:(keep = variable1 variable2)。当作为statement时,不需要括号也不需要等号,比如:keep variable1 variable2。

Leave a Reply

Your email address will not be published. Required fields are marked *