SAS Base (21)

Given the SAS data set WORK.PRODUCTS:

ProdId Price ProductType Sales Returns
K12S 95.50 OUTDOOR 15 2
B132S 2.99 CLOTHING 300 10
R18KY2 51.99 EQUIPMENT 25 5
3KL8BY 6.39 OUTDOOR 125 15
DY65DW 5.60 OUTDOOR 45 5
DGTY23 34.55 EQUIPMENT 67 2

The following SAS program is submitted:

data WORK.OUTDOOR WORK.CLOTH WORK.EQUIP;
set WORK.PRODUCTS;
if Sales GT 30;
if ProductType EQ ‘OUTDOOR’ then output WORK.OUTDOOR;
else if ProductType EQ ‘CLOTHING’ then output WORK.CLOTH;
else if ProductType EQ ‘EQUIPMENT’ then output WORK.EQUIP;
run;

How many observations does the WORK.OUTDOOR data set contain?
A. 1
B. 2
C. 3
D. 6

Check Answer
Answer: B

注解:Outdoor data set中的数据需要满足2个条件,Sales大于30以及ProductType为OUTDOOR,只有第四和第五个observation满足条件。

SAS Base (20)

The data set WORK.REALESTATE has the variable LocalFee with a format of 9. and a variable CountryFee with a format of 7.;

The following SAS program is submitted:

data WORK.FEE_STRUCTURE;
format LocalFee CountryFee percent7.2;
set WORK.REALESTAT;
LocalFee=LocalFee/100;
CountryFee=CountryFee/100;
run;

What are the formats of the variables LOCALFEE and COUNTRYFEE in the output dataset?
A. LocalFee has format of 9. and CountryFee has a format of 7.
B. LocalFee has format of 9. and CountryFee has a format of percent7.2
C. Both LocalFee and CountryFee have a format of percent7.2
D. The data step fails execution; there is no format for LocalFee.

Check Answer
Answer: C

注解:FORMAT statement可以一次改变多个变量的format。此外,假设原始值是10,那么Format改成percent7.2之后,输出的结果则为1000%。

SAS Base (19)

The SAS data set WORK.ONE contains a numeric variable named Num and a character variable named Char:

Num Char
1 23
2 23
1 77

The following SAS program is submitted:

proc print data=WORK.ONE;
where Num=’1′;
run;

What is output?

A.

Obs Num Char
1 1 23

B.

Obs Num Char
1 1 23
3 1 77

C.

Obs Num Char
1 1 23
2 2 23
3 1 77

D. No output is generated.

Check Answer
Answer: D

注解:数值型无法和字符型进行逻辑运算(例如:比大小),并且WHERE statement不会自动将字符型转换成数值型。Log中会显示”ERROR: WHERE clause operator requires compatible variables.”。

SAS Base (18)

Which statement describes a characteristic of the SAS automatic variable _ERROR_?

A. The _ERROR_ variable maintains a count of the number of data errors in a DATA step.
B. The _ERROR_ variable is added to the program data vector and becomes part of the data set being created.
C. The _ERROR_ variable can be used in expressions in the DATA step.
D. The _ERROR_ variable contains the number of the observation that caused the data error.

Check Answer
Answer: C

注解:和SAS Base (15)类似

SAS Base (17)

Given the following data step:

data WORK.GEO;
infile datalines;
input City $20.;
if City=’Tulsa’ then
State=’OK’;
Region=’Central’;
if City=’Los Angeles’ then
State=’CA’;
Region=’Western’;
datalines;
Tulsa
Los Angeles
Bangor
;
run;

After data step execution, what will data set WORK.GEO contain?

A.

Obs City State Region
1 Tulsa OK Western
2 Los Angeles CA Western
3 Bangor Western

B.

Obs City State Region
1 Tulsa OK Western
2 Los Angeles CA Western
3 Bangor

C.

Obs City State Region
1 Tulsa OK Central
2 Los Angeles CA Western
3 Bangor Western

D.

Obs City State Region
1 Tulsa OK Central
2 Los Angeles CA Western
3 Bangor
Check Answer
Answer: A

注解:程序对Region进行了2次赋值操作,第一次赋值为Central,第二次赋值操作覆盖了第一次的值,把Region改为了Western。另外需要注意的是,题目中的IF/THEN语句,在完成对State的复制后就结束了,对Region的赋值语句并不受IF/THEN的影响。如需输出D中的结果,程序应改为:

data WORK.GEO;
infile datalines;
input City $20.;
if City=’Tulsa’ then do;
State=’OK’;
Region=’Central’;
end;
if City=’Los Angeles’ then do;
State=’CA’;
Region=’Western’;
end;
datalines;
Tulsa
Los Angeles
Bangor
;
run;

SAS Base (16)

The following SAS program is submitted:

data WORK.DATE_INFO;
X=’04jul2005’d;
DayOfMonth=day(x);
MonthOfYear=month(x);
Year=year(x);
run;

What types of variables are DayOfMonth, MonthOfYear, and Year?

A. DayOfMonth, Year, and MonthOfYear are character.
B. DayOfMonth, Year, and MonthOfYear are numeric.
C. DayOfMonth and Year are numeric. MonthOfYear is character.
D. DayOfMonth, Year, and MonthOfYear are date values.

Check Answer
Answer: B

注解:d的作用是将“数字day + 英文month前三个字母 + 数字year”格式的日期,转化成SAS日期,即以1960年1月1日为0,2005年7月4日则为16621。DAY, MONTH, YEAR这三个function则是分别返回一个SAS格式日期的日,月,年,并且返回的值均为数值型。

SAS Base (15)

Which statement is true concerning the SAS automatic variable _ERROR_?

A. It cannot be used in an if/then condition.
B. It cannot be used in an assignment statement.
C. It can be put into a keep statement or keep= option.
D. It is automatically dropped.

Check Answer
Answer: D

注解:_ERROR_是DATA step中SAS生成的Automatic Variable,当程序运行正常时_ERROR_的值为0,出错时为1。_ERROR_仅在DATA step的执行过程中存在,在执行完一次DATA step输出数据时,SAS自动丢弃该变量,即输出的data set中不会出现_ERROR_这一变量。在DATA step的执行过程中,_ERROR_可以当作IF/THEN的条件,可以将其值赋给其它变量输出到data set中,但KEEP无法作用于_ERROR_。

SAS Base (14)

Which of the following programs correctly invokes the DATA Step Debugger:

A.
data WORK.TEST debug;
set WORK.PILOTS;
State=scan(cityState,2,’ ‘);
if State=’NE’ then description=’Central’;
run;

B.
data WORK.TEST debugger;
set WORK.PILOTS;
State=scan(cityState,2,’ ‘);
if State=’NE’ then description=’Central’;
run;

C.
data WORK.TEST / debug;
set WORK.PILOTS;
State=scan(cityState,2,’ ‘);
if State=’NE’ then description=’Central’;
run;

D.
data WORK.TEST / debugger;
set WORK.PILOTS;
State=scan(cityState,2,’ ‘);
if State=’NE’ then description=’Central’;
run;

Check Answer
Answer: C

注解:/ DEBUG用于帮助识别程序逻辑错误和某些数据错误,记住格式即可。

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是新建立的变量。

SAS Base (12)

The Excel workbook QTR1.XLS contains the following three worksheets:
JAN
FEB
MAR

Which statement correctly assigns a library reference to the Excel workbook?
A. libname qtrdata ‘qtr1.xls’;
B. libname ‘qtr1.xls’ sheets=3;
C. libname jan feb mar ‘qtr1.xls’;
D. libname mydata ‘qtr1.xls’ WORK.heets=(jan,feb,mar);

Check Answer
Answer: A

注解:使用Excel SAS/ACCESS LIBNAME Engine读取Excel文件的格式:LIBNAME  libref  ‘文件路径’。