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;

One thought to “SAS Base (17)”

  1. Really appreciate your answers. But I am finding it hard to understand the explanation of all answers as the language is not just english. Any solution for that?

Leave a Reply

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