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  ‘文件路径’。

SAS Base (11)

The following SAS program is submitted:

data course;
input exam;
datalines;
50.1
;
run;

proc format;
value score 1 – 50 = ‘Fail’
51 – 100 = ‘Pass’;
run;

proc report data =course nowd;
column exam;
define exam / display format=score.;
run;

What is the value for exam?
A. Fail
B. Pass
C. 50.1
D. No output

Check Answer
Answer: C

注解:自定义format Score只定义了1至50、51至100这两个区间,50.1并不在这两个区间之内,所以输出的时候依然显示50.1。

SAS Base (10)

Given the existing SAS program:

proc format;
value agegrp
low-12 =’Pre-Teen’
13-high = ‘Teen’;
run;

proc means data=SASHELP.CLASS;
var Height;
class Sex Age;
format Age agegrp.;
run;

Which statement in the proc means step needs to be modified or added to generate the following results:

Analysis Variable : Height
Sex Age N Obs Minimum Maximum Mean
F Pre-Teen 3 51.3 59.8 55.8
  Teen 6 56.5 66.5 63.0
M Pre-Teen 4 57.3 64.8 59.7
  Teen 6 62.5 72.0 66.8

A. var Height / nobs min max mean maxdec=1;
B. proc means data=SASHELP.CLASS maxdec=1 ;
C. proc means data=SASHELP.CLASS min max mean maxdec=1;
D. output nobs min max mean maxdec=1;

Check Answer
Answer: C

注解:PROC MEANS默认会输出非missing观测值个数、均值、标准差、最小值和最大值。题目只需要输出最小值(MIN)、最大值(MAX)和均值(MEAN),并显示小数点后一位(MAXDEC)。其中N Obs是观测值个数(包括missing和非missing),要去掉的话使用NONOBS,即proc means data = XXXX nonobs。

SAS Base (9)

The following SAS program is submitted:

data WORK.RETAIL;
Cost=’$20.000′;
Discount=.10*Cost;
run;

What is the result?

A. The value of the variable Discount in the output data set is 2000.No messages are written to the SAS log.
B. The value of the variable Discount in the output data set is 2000.A note that conversion has taken place is written to the SAS log.
C. The value of the variable Discount in the output data set is missing.A note in the SAS log refers to invalid numeric data.
D. The variable Discount in the output data set is set to zero.No messages are written to the SAS log.

Check Answer
Answer: C

注解:由于Cost是字符型变量,只有数值型变量才能参与数学运算,SAS会尝试将字符型转换成数值型,但由于Cost中有一个$,SAS无法完成类型转换。如果把$去掉,结果则会完全不同。

SAS Base (8)

The SAS data set named WORK.SALARY contains 10 observations for each department,and is currently ordered by Department. The following SAS program is submitted:

data WORK.TOTAL;
set WORK.SALARY(keep=Department MonthlyWageRate);
by Department;
if First.Department=1 then Payroll=0;
Payroll+(MonthlyWageRate*12);
if Last.Department=1;
run;

Which statement is true?
A. The by statement in the DATA step causes a syntax error.
B. The statement Payroll+(MonthlyWageRate*12); in the data step causes a syntax error.
C. The values of the variable Payroll represent the monthly total for each department in the WORK.SALARY data set.
D. The values of the variable Payroll represent a monthly total for all values of WAGERATE in the WORK.SALARY data set.

Check Answer
Answer: C

注解:和SAS Base (1)类似。