SAS Base (48)

The following SAS program is submitted:

data WORK.TEST;
drop City;
infile datalines;
input Name $ 1-14 / Address $ 1-14 / City $ 1-12 ;
if City=’New York ‘ then input @1 State $2.;
else input;
datalines;
Joe Conley
123 Main St.
Janesville
WI
Jane Ngyuen
555 Alpha Ave.
New York
NY
Jennifer Jason
666 Mt. Diablo
Eureka
CA
;
run;

What will the data set WORK.TEST contain?

A.

Obs Name Address State
1 Joe Conley 123 Main St.
2 Jane Ngyuen 555 Alpha Ave. NY
3 Jennifer Jason 666 Mt. Diablo

B.

Obs Name Address City State
1 Joe Conley 123 Main St. Janesville
2 Jane Ngyuen 555 Alpha Ave. New York NY
3 Jennifer Jason 666 Mt. Diablo Eureka

C.

Obs Name Address State
1 Jane Ngyuen 555 Alpha Ave. NY

D. No observations, there is a syntax error in the data step.

Check Answer
Answer: A

注解:INPUT statement中,$表示这是一个字符型变量;1-14表示将该行的第1-14个字符写进变量;/表示将指针移动到下一行的第一个字符,即之后的变量将从下二行的第一个字符开始读取。INPUT statement默认自动前往下一行,当INPUT后没有申明任何变量名时,其起到的作用和/类似,但两者的工作原理不同,具体请查看官方手册中INPUT statement的Without Arguments部分。题目中的程序首先逐行读取Name,Address和City,只有在City为New York时读取State的值,最后DROP statement告诉SAS不要向data set中写入City这个变量。

SAS Base (33)

The following SAS program is submitted:

data WORK.TEST;
set WORK.PILOTS;
if Jobcode=’Pilot2′ then Description=’Senior Pilot’;
else Description=’Unknown’;
run;

The value for the variable Jobcode is: PILOT2. What is the value of the variable Description?
A. PILOT2
B. Unknown
C. Senior Pilot
D. ‘ ‘ (missing character value)

Check Answer
Answer: B

注解:字符串的大小写是有区别的,所以PILOT不等于Pilot,执行ELSE之后的表达式。

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 (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;