SAS Base (49)

The following SAS program is submitted:

data WORK.TOTALSALES(keep=MonthSales{12});
set WORK.MONTHLYSALES(keep=Year Product Sales);
array MonthSales{12};
do i=1 to 12;
MonthSales{i}=Sales;
end;
drop i;
run;

The program fails execution due to syntax errors.
What is the cause of the syntax error?
A. An array cannot be referenced on a keep= data set option.
B. The keep= data set option should be (keep=MonthSales*).
C. The keep= data set option should be the statement KEEP MonthSales{12}.
D. The variable MonthSales does not exist.

Check Answer
Answer:  A

注解:KEEP和DROP的对象不能是数组,只能是变量。如果希望去掉数组中的变量,可以直接引用该变量的名字。例如题目中,希望仅保留数组中第12个元素,即MonthSales{12},可以使用以下KEEP option: KEEP = MonthSales12,如果想保留整个数组:KEEP = MonthSales1 – MonthSales12。

SAS Base (39)

The following SAS program is submitted:

data WORK.AUTHORS;
array Favorites{3} $ 8 (‘Shakespeare’,’Hemingway’,’McCaffrey’);
run;

What is the value of the second variable in the dataset WORK.AUTHORS?
A. Hemingway
B. Hemingwa
C. ‘ ‘ (a missing value)
D. The program contains errors. No variables are created.

Check Answer
Answer: B

注解:ARRAY statement中,Favorites为数组名字,{3}表示数组中有3个元素,$表示数组中的元素为字符型,8表示数组内的值最长为8个字节,(‘Shakespeare’,’Hemingway’,’McCaffrey’)设定数组元素的初始值。第二个数组元素,即 Favorites{2},得到的初始值为’Hemingway’,但由于定义了最长8个字符,所以其值为Hemingwa。

SAS Base (13)

The following SAS program is submitted:

data WORK.TEST;
set WORK.MEASLES(keep=Janpt Febpt Marpt);
array Diff{3} Difcount1-Difcount3;
array Patients{3} Janpt Febpt Marpt;
run;

What new variables are created?
A. Difcount1, Difcount2 and Difcount3
B. Diff1, Diff2 and Diff3
C. Janpt, Febpt, and Marpt
D. Patients1, Patients2 and Patients3

Check Answer
Answer: A

注解:ARRAY statement用于定义Array内的元素。题目中,Janpt, Febpt和Marpt是来自于Measles data set的旧变量,仅有Difcount1, Difcount2和Difcount3是新建立的变量。