SAS Base, A00-211 Crambible, SAS 크램바이블

SAS 베이스 자격증, SAS 문제풀이 


QUESTION NO: 142

The following SAS program is submitted: 


data work.clients;
calls = 6;
do while (calls le 6);

calls + 1;
end;
run;

Which one of the following is the value of the variable CALLS in the output data set?

A. 4 

B. 5 

C. 6 

D. 7



work라이브러리에 client 데이타를 만들려고 하는데요. 이때 call이라는 변수에 6을 넣었습니다. 그리고 do 반복문을 실행하는데 이때 call이라는 변수가 6보다 less than equal 6보다 작을때까지 반복하려고 합니다. 6에서 반복문이 시작되어서 calls+1 = 7이 되었고요. 다시 do 반복문을 실행하려고 하니 이미 조건 7 이 less than equal 이 만족하지 않아서 do 반복문이 실행되지 않고 그대로 끝나게 됩니다. 





같은 결과값을 얻기 위해 DO WHILE이 아닌 DO UNTIL을 쓸 경우 어떤 값을 바꾸면 될까요? 


DO WHILE / DO UNTIL 이랑 비교해봅시다. 

참고: http://www2.sas.com/proceedings/forum2007/067-2007.pdf 


DO WHILE : The while test is evaluated at the top of the loop. 

DO UNTIL: The until test is evaluated at the bottom of the loop.
 

while은 loop반복문 위에서 조건값을 확인하고, 

until은 loop 반복문 아래에서 조건값을 확인해야합니다. 


그래서 while경우, call의 값 6으로 할당된걸로 시작해서 반복문에 들어와 7이 되었고 이 값이 do while (call le 6)에서 less than or equal 6 에서 조건이 만족되지 않아 7로 결과값이 나왔죠. 


똑같이 7의 결과값을 얻으려면, until의 경우, do until (call ge 6) 이라고 설정합니다. 이때, ge는 greater or equal to라는 뜻이고요. call값이 6으로 할당된걸로 시작해서 반복문에 들어와 7이 되었습니다. 7의 값을 다시 do 반복문 처음으로 올라가 이 값이 조건되는지를 확인하는게 아니라 조건문이 do loop 안에 들어온 값이 만족될때를 설정하는거라 LE이 아니라 GE로 바꿔주면 됩니다.   





Answer: D 


반응형

SAS Base, A00-211 Crambible, SAS 크램바이블

SAS 베이스 자격증, SAS 문제풀이 



QUESTION NO: 141

The SAS data set BANKS is listed below: 


BANKS
name rate
FirstCapital 0.0718 

DirectBank 0.0721
VirtualDirect 0.0728

The following SAS program is submitted: 

data newbank;
do year = 1 to 3;
set banks;
capital + 5000;

end;
run;


Which one of the following represents how many observations and variables will exist in the SAS data set NEWBANK?


A. 0 observations and 0 variables

B. 1 observations and 4 variables 

C. 3 observations and 3 variables 

D. 9 observations and 2 variables



Bank라는 데이타안에 name과 rate이라는 변수가 있습니다. 이 데이터를 불러 이용해서 newbank 데이터를 만들려고 합니다. do 반복문을 보면, 로 year 변수가 1부터 3까지, capital 이라는 변수도 새로 생겼네요.  그래서 총 변수는 4개가 됩니다. 


이때 do 반복문에서 output이 없어서 이 결과물을 보내지 않고 계속 덮어씌우게 됩니다. 그래서 마지막 observation만 기록된 채로 do 반복문이 끝나게 되면서 결과물은 아래처럼 나오게 되어요. 


참고로 위에는 BANK데이타, 그 아래는 NEWBANK데이타 입니다.  





data sasuser.banks;

input name : $13. rate : 6.4;

cards;

FirstCapital 0.0718

DirectBank 0.0721

VirtualDirect 0.0728

;

run;

proc print;

run;


data sasuser.bank_new;

do year = 1 to 3;

set sasuser.banks;

capital + 5000;

end;

run;

proc print data=sasuser.bank_new;

run;




Answer: B 



반응형

SAS Base, A00-211 Crambible, SAS 크램바이블

SAS 베이스 자격증 



QUESTION NO: 140

A realtor has two customers. One customer wants to view a list of homes selling for less than $60,000. The other customer wants to view a list of homes selling for greater than $100,000. Assuming the PRICE variable is numeric, which one of the following PRINT procedure steps will select all desired observations?


A. proc print data =sasuser.houses; 

    where price lt 60000;
    where price gt 100000;
    run;


B. proc print data =sasuser.houses; 

    where price lt 60000 or price gt 100000; 

    run;


C. proc print data =sasuser.houses;
    where price lt 60000 and price gt 100000; 

    run;


D. proc print data =sasuser.houses;
    where price lt 60000 or where price gt 100000; 

    run;


리얼터가 한명의 고객에게는 $60,000 이하의 주택 가격 리스트를, 한명의 고객에겐 $100,000 이상의 주택 가격 리스트를 제공하려고 합니다. 이때 Price가 수치형 변수일때 어떤 방법으로 프린트를 하면 되는지에 관한 질문입니다. 


60,000 이하 또는 (or) 100,000 이상이니까 C는 해당되지 않겠지요. and 는 두 조건 둘 다 해당되는걸 말하는거라서 이때 값은 0으로 나옵니다. 


같은 변수 안에서, 즉 price라는 변수안에서 여러개의 값을 비교해서 프린트하고 싶으면 where price lt 60000 or price gt 100000 즉, where 조건문 뒤에 변수명을 적은 후, lt = less than 그 뒤에 값 or 변수명을 적은 후, gt = greater than 뒤에 값 이렇게 적으면 됩니다. 



Answer: B 


반응형

SAS Base, A00-211 Crambible 

SAS 베이스 자격증


QUESTION NO: 92


The following code was modified to generate the results further below: 


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;


The following results were generated to display only specific statistics and limit the decimals with the modification: Which statement below was modified or added to generate the results above:



A. var Height / nobs min max mean max dec=1;

B. proc means data=SASHELP.CLASSmaxdec=1 ;
C. proc means data=SASHELP.CLASS min max mean maxdec=1; 

D. outputnobs min max mean maxdec=1;



proc format 을 사용해서 agegrp라는 포맷을 정의하고 있습니다. 

proc means 명령어를 SASHELP라는 라이브러리에 있는 CLASS라는 데이터에 적용하려고 하는데요. 이때 대상 변수는 Height이고요. 성별과 나이로 지정하고 Age는 agegrp.라는 포맷을 사용하려고 합니다. 


결과물을 보면 원하는 통계량만 지정하고요. 해당 통계값은 소숫점이 하나만 보이려고 합니다. 


Answer: C 


반응형

SAS Base, A00-211 Crambible 

SAS 베이스 자격증


QUESTION NO: 91

The following program is submitted:


proc sort data=SASUSER.PROJECTS out=PSORT;

by Code descending Date Cost;
run;


Which of the following is true concerning the submitted program?


A. The descending option applies to the variable Code.
B. The variable Code is sorted by ascending order.
C. The PSORT data set is stored in the SASUSER library.
D. The descending option applies to the Date and Cost variables.


sasuser라이브러리에 있는 projects 파일을 정렬을 해서 work라이브러리에 있는 psort라는 파일로 내보내려고 합니다. 이때 by를 이용해서 Code는 오름차순으로, Date는 내림차순으로, Cost는 오름차순으로 정렬이 되고 있네요. 


이렇게 정렬할때 아무런 값이 없으면 default로 오름차순이 되고 있고요. 

내림차순으로 지정하고 싶으면 변수 앞에 지정해주면 됩니다. 


Answer: B 


반응형

+ Recent posts