SAS Base, A00-211 Crambible 

SAS 베이스 자격증 


QUESTION NO: 76


Which statement specifies that records 1 through 10 are to be read from the raw data file customer.txt?


A. infile 'customer.txt' 1-10;
B. input 'customer.txt' stop@10; 

C. infile 'customer.txt' obs=10; 

D. input 'customer.txt' stop=10;


구문 중에서 어떤 구문이 자료 obs1부터 10까지 읽는지 찾는 문제인데요. infile로 파일을 불러오고 obs를 10으로 지정해주면 됩니다. 즉, 10번 obs까지라고 불러오는데 어디서부터 불러오라는지 지정되어있지 않아서 default 값으로 첫번째 값부터 불러오게 됩니다. 


만약 firstobs를 지정해주고 싶으면, 다음처럼 firstobs=숫자 를 넣어주면 됩니다.  

infile 'customer.txt' firstobs=숫자 obs=10; 



Answer: C


반응형

SAS Base, A00-211 Crambible 

SAS 베이스 자격증 


QUESTION NO: 75

Given the raw data record in the file phone.txt: 


----|----10---|----20---|----30---|
Stevens James SALES 304-923-3721 14


The following SAS program is submitted:


data WORK.PHONES; 

infile phone.txt;

input EmpLName $ EmpFName $ Dept $ Phone $ Extension;
<_insert_code_>
run;


Which SAS statement completes the program and results in a value of "James Stevens" for the variableFullName?


A. FullName=CATX(' ',EmpFName,EmpLName); 

B. FullName=CAT(' ',EmpFName,EmpLName); 

C. FullName=EmpFName!!EmpLName;
D. FullName=EmpFName + EmpLName;


infile로 phone.txt라는 파일을 불러와서 work라이브러리에 phones라는 데이터를 만들려고 합니다. input을 이용해서 변수들을 선언하고 있고요. 원하는것은 FullName라는 변수가 있는데 이 변수의 값이 James Stevens가 되도록 하려는거네요. 


문자열 결합 방법에 대한 질문이고요. 문자끼리 결합하려고 할때  catx, cat, !! 를 사용하면 됩니다. 


지금 첫번째 변수랑 두번째 변수 더하면 되겠는데요. EmpLName, EmpFName을 어떻게 더해야하냐면, 


CATX(' ',EmpFName,EmpLName)

catx는 문자열 결합할때 결합할때 공백을 제거해서 더하고요. 이때 첫번째 지정이 구분자가 되어서 연결됩니다. 따라서 James Stevens가 되겠네요. 


CAT(' ',EmpFName,EmpLName)

경우, 공백없이 그냥 주르륵 합치게 됩니다. 그래서 길이가 default값으로 8자리인데요. 공백부분도 같이 들어가는거라 공백이면 공백이라고 적어보겠습니다. 그리고 앞에 있는건 구분자가 아니고요. 

공백James 공백공백공백Stevens공백 이렇게 됩니다.  


EmpFName!!EmpLName;

경우, 공백제거하는 기능은 없고 위에 CAT기능과 같습니다. 


문자끼리 합칠때는 숫자형 합치는거, + 이걸 쓸 수 없습니다. 


Answer: A 


반응형

SAS Base, A00-211 Crambible 

SAS 베이스 자격증 

QUESTION NO: 74


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


work 라이브러리에 test라는 데이타를 만들려고 합니다. set으로 measles라는 데이타를 불러올때 keep을 이용해서 Janpt, Febpt, Marpt 변수를 유지하고요. 


array를 이용해서 Diff라는 배열(array)을 만드는데 이때, {3} 즉, 배열의 길이는 3이고요. 각 배열마다 변수가는데 그 변수 이름이 Difcount1, Difcount2, Difcount3 라는거죠. 


또 array를 이용해서 Patients라는 배열의 길이 3의 배열을 만드느데 이때 Janpt Febpt Marpt 변수가 각 배열로 들어가게 됩니다. 


따라서 새롭게 만들어진 변수는 A가 되겠습니다. 


Answer: A 



반응형

SAS Base, A00-211 Crambible 

SAS 베이스 자격증 


QUESTION NO: 73

Given the contents of the raw data file TYPECOLOR.DAT:

 ----+----10---+----20---+----30 

daisyyellow 


The following SAS program is submitted: 

data FLOWERS;

infile'TYPECOLOR.DAT' truncover;
length 
Type $ 5 Color $ 11; 

input Type $ Color $; run;


What are the values of the variables Type and Color?


A. Type=daisy, Color=yellow
B. Type=daisy, Color=w
C. Type=daisy, Color=daisyyellow 

D. Type=daisy, Color=


raw 데이타로 typecolor가 있고요. infile로 typecolor파일을 불러와서 FLOWERS라는 데이터를 만들려고 합니다. 이때 truncover라는 옵션이 걸려있네요. 


length를 type은 길이가 5, color는 길이가 11로 지정되어있는데요. 그런데 raw file의 데이타를 보면 daisyyellow로 11자리네요. 그럼 type으로 길이가 5로 지정되어서 daisy까지 들어가게 됩니다. 그런데 truncover 옵션이 없으면 color에서 에러가 나게 됩니다. 왜냐하면 raw 데이타 daisyyellow만 들어가있어서 일단 type을 읽었는데 color에 읽을 데이타가 없어서 에러가 난겁니다. 


읽을 데이타가 없어서 에러가 나는걸 방지하는게 truncover 역할입니다. 그러니까 다음행으로 넘어가지 말고 읽지 않도록 하는거죠. 그래서 type에는 daisy라고 들어가있고, 그 다음 불러올 데이타가 없지만 에러는 뜨지 않고 그냥 missig value라고만 들어가있도록 color에는 아무런 값이 들어가있지 않게 됩니다. 



Answer: D 


반응형

SAS Base, A00-211 Crambible 

SAS 베이스 자격증


QUESTION NO: 72


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.


각 부서(department)별로 10개의 observations이 있고요. by를 이용해서 부서들이 정렬이 되어있습니다. 


이때 sas 코드를 보면, work 라이브러리에 있는 salary 데이터에서 keep을 이용해서 department, monthlywagerate 변수를 가져옵니다. 그리고 다시 by를 이용해서 department별로 오름차순으로 정렬하고요. (default값이 오름차순입니다) 


이렇게 set & by 에서 정렬이 되어있으면 각 부서마다 처음나오는 observation과 같은 부서의 마지막에 나오는 observation이 pdv상에 생기게 됩니다. 잘 모르시면 first/ last 문제 반복해서 나오고 있으니 확인해보세요. 


문제에서 각 부서마다 10개의 observation이 있다고 했으니 하나의 부서에서 첫번쨰 나오는 값이 first, 같은 부서 마지막에 나오는 값이 last라는걸로 표시가 되는거예요. 이 기능은 각 부서별로 wagerate을 누적해서 더한 값을 구하려고 할때 얘네들이 잘 활용이 됩니다. 


워낙 반복적으로 나오는 문제니까 다른문제 참고하시라 생각하면서~ 이만 줄일게요.  



Answer: C 


반응형

+ Recent posts