본문 바로가기

자격증/SAS BASE

SAS 관련 정리

1. 실행 단축키 : F3

2. 주석 달기 : Ctrl + / 

 

3. Footnote statment

: output 에서 아랫부분의 데이터와 상관없이 설정한 문자값을 보여주는 명령어

 

 

   footnote1 'Sales Report for Last Month'

   footnote2 'Selected Products Only'

   footnote3   ~

   footnote4   ~

  

proc print data = sasuser.shoes;

footnote2  'All Products';

run;

 

처음에 footnote 가 1~4 까지 지정. PROC PRINT 다음에 footnote2 가 재설정 되었음. 

2번이 재설정 되었으면 그 하위단계는 삭제된다.  2번이 재설정되었으므로 3~4번은 삭제되고 1~2번만 남는다.

 

Q. Which footnote(s) is/are displayed in the report?

     (Sales Report for last Month All Products)

 

 

출처 : https://statnmath.tistory.com/164

 

[A00-211, SAS Crambible] SAS Q5 - footnote 문제풀이

SAS Base, A00-211 Crambible,SAS 크램바이블, SAS 베이스 자격증 문제풀이 QUESTION NO: 5 The following SAS program is submitted: footnote1 'Sales Report for Last Month'; footnote2 'Selected Products Only'; footnote3 'All Regions'; footnote4 'Al

statnmath.tistory.com

 

 

 

4. PUT, INPUT 

문자형 → 숫자형 : INPUT(변수, 길이)

숫자형 →문자형 : PUT(변수, 길이)

 

 

5. Transwrd

: transwrd는 LENGTH 를 200으로 맞추고, 문자를 바꾸는 역할을 한다.

 변수 = transwrd (변수, 바꾸고 싶은 문자, 바꾼 후의 문자);

 

data one;

  addressl = '214 London Way';

run;

 

data one;

   set one;

   address = transwrd(addressl, "Way", "Drive");

run;

 

Q. What are the length and value of the variable ADDRESS?

    (Length : 200, value : '214 London Drive')

 

 

출처 : https://statnmath.tistory.com/166

 

[A00-211, SAS Crambible] SAS Q7 - tranward 문제풀이

A00-211 Crambible DumpSAS 크램바이블 덤프, SAS 베이스 자격증 문제풀이 QUESTION NO: 7 The following SAS program is submitted: data one; addressl= '214 London Way'; run; data one; set one; address = tranwrd(address1, 'Way', 'Drive'); run; Wh

statnmath.tistory.com

 

 

6. DO UNTIL

: 조건문과 상관없이 반복문을 먼저 실행함.

: DO WHILE 은 조건문 먼저 살피게 된다.

 

 

data work.sets;

  do until (prod gt 6);

  prod + 1 ;

  end;

  run;

 

 

Q. What is the value of the variable PORD in the output data set?   (7)

  • 조건문 prod gt 6 (prod 값이 6보다 큰지) 을 살펴보는 것이 아니라 바로 prod + 1 부터 시작함
  • 이때 prod 값을 미리 설정하지 않았기 때문에 초기값이 0 이므로 0 부터 시작하게 된다.
  • 1이 6보다 큽니까? 라는 조건이 만족되지 않았기 때문에 반복하게 된다.
  • 반복하다가 prod 가 7이 된 순간 조건문을 만족하므로 end 로 반복구문이 끝난다. 따라서 prod 값은 7.
  •  DO UNTIL은 일단 실행하고 결과값을 조건문과 비교한다 !!

 

Q. 만약 질문이 DO WHILE 이였다면?

  • DO WHILE 은 조건문 먼저 살핀다. 조건문부터 만족되면 그 다음 반복문이 실행된다.
  • 우선 prod의 초기값은 0, 조건문 ( 0 > 6 ) 이 만족되지 않으므로 반복문지 되지 않고 바로 빠져나오게 된다.
  • 따라서 prod 값은 0. 

 

 

출처 : https://statnmath.tistory.com/167

 

[A00-211, SAS Crambible] SAS Q8 - do until 문제풀이

SAS Base, A00-211 Crambible 덤프SAS 크램바이블, SAS 베이스 자격증 문제풀이 QUESTION NO: 8 The following SAS program is submitted: data work.sets; do until (prod gt 6); prod + 1; end; run; What is the value of the variable PROD in the outpu

statnmath.tistory.com

 

 

 

7. Rename

: 데이터셋 MERGE 할 때 변수이름을 바꾸고 싶다면 rename 사용

 

Q. work.salary 데이터의 name 변수를 fname으로 바꾸는 코드

merge work.employee  work.salary(rename = (name=fname));

 

 

출처 : https://statnmath.tistory.com/168

 

[A00-211, Crambible] SAS Q9

SAS Base, A00-211 Crambible SAS 베이스 자격증 QUESTION NO: 9 The SAS data sets WORK.EMPLOYEE and WORK.SALARY are shown below: WORK.EMPLOYEE WORK.SALARY fnameage name salary Bruce 30 Bruce 25000 Dan 40 Bruce 35000 Dan 25000 The following SAS program i

statnmath.tistory.com

 

 

 

8. PROC CONTETNS DATA = 데이터셋 ; RUN;

Q. SASUSER 라이브러리에 있는 모든 data lising 보기

 

proc contents data=sasuser._all_;

run;

 

  • 라이브러리의 데이터셋 속성을 한번에 확인할 수 있다.
  • 만약 sasuser.all 이라면 all 이라는 데이터의 이름이 불러와진다.

 

 

 

9. MERGE 시 데이터 정렬에 관하여

proc sort data= work.employee;

by descending fname;

proc sort data = work.salary;

by descending fname;

 

data work.empdata;

  merge work.employee   work.salary;

  by fname;

run;

 

 

Q. Why does the program fail to execute?

  • Work.employee, Work.salary 데이터셋이 fname 변수를 기준으로 내림차순 정렬하였지만,
  • MERGE 명령어를 통해 두 데이터셋을 fname 변수를 기준으로 오름차순 정렬하려고 했기 때문

 

출처 : https://statnmath.tistory.com/170

 

[A00-211, Crambible] SAS Q11

SAS Base, A00-211 Crambible SAS 베이스 자격증 QUESTION NO: 11 The following SAS program is submitted: proc sort data = work.employee; by descending fname;proc sort data = work.salary; by descending fname; data work.empdata; merge work.employee work.s

statnmath.tistory.com

 

 

 

10.  Infile Satatement 의 Delimiter (dlm) 옵션

 

Given the following raw data record:

 

     -------|----10----|----20----|----30

    sonl, Travis

 

Q. The following output is disired.

 

     Obs relation firstname

     1 son Travis

 

 

data family ;

infile 'file specification' dlm=','   -------------→ dlm 은 infile 다음에 와야 한다 !!

input relation $ firstname $ ;

run ;

 

 

출처 : https://statnmath.tistory.com/172

 

[A00-211, Crambible] SAS Q13

SAS Base, A00-211 Crambible SAS 베이스 자격증 QUESTION NO: 13 Given the following raw data record: ----I----10---I----20---I----30 son, Travis The following output is desired: Obs relation firstname 1 son Travis Which SAS program correctly reads in t

statnmath.tistory.com

 

 

 

11. LENGTH statement 

The WORK.DEPARTMENT data set contains a character variable named JOBCODE with a lenth of 5.

 

data work.accounting;

   set work.department;

   length jobcode $12;

   jobcode = "FAI";

run;

 

 

Q. jobcode 의 길이는?  (5)

  • set 으로 불러오게 되는 work.department 에는 길이가 5로 설정된 jobcode가 이미 있다 !!
  • length jobcode $12 는 DATA 와 SET 구문 사이에 들어가야 효력이 발생한다 !!

 

 

출처 : https://statnmath.tistory.com/175

 

[A00-211, Crambible] SAS Q16

SAS Base, A00-211 Crambible SAS 베이스 자격증 QUESTION NO: 16 The following SAS program is submitted: data work.accounting; set work.department; length jobcode $ 12; jobcode='FAl'; run; The WORK.DEPARTMENT data set contains a character variable named

statnmath.tistory.com

 

 

 

 

12. ODS (Output Delivery System)

: 결과물을 HTML, PRF, PDF, EXCEL 등으로 내보내주는 옵션역할을 한다.

: ODS 를 사용하여 HTML 파일로 보낼 때, CLOSE option 을 통해 종료시킨다.

 

 

 

 

13. 결측값 (MIssing Value)  표현법

  • Numeric missing values : a single period (.).
  • Character missing values : a single blank enclosed in quotes (' ').

 

 

 

14. Missing 값이 존재할 때 SUM(a+b) 와 a+b 결과값의 차이점

data work.passengers;

if OrigPassengers = then OrigenPassengers = 100;    -------------→ OrigPassengers가 missing value 이면 값에 100 할당

TransPassengers = 100;

OrigPassengers = .;  -------------→ 다시 missing value 할당

TotalPassengers = sum(OrigPassengers, TransPassengers) + 0;

run;

 

Q. What is the value of the TotalPassengers variable in the output data set?  (100)

  • SUM(a,b)의 경우, missing value 를 무시함 (1 + . = 1)
  • a + b 의 경우,  하나가 missing value 이면 결과값도 missing value.   (1 + . = .)

 

TotalPassengers = sum(OrigPassengers, TransPassengers) + 0; 는

sum (OrigPassengers, TransPassengers) 

sum(missing value,100) +100

100 + 0

100

 

 

 

출처 : https://statnmath.tistory.com/178

 

[A00-211, Crambible] SAS Q19 - sum (a+b)

SAS Base, A00-211 Crambible SAS 베이스 자격증 QUESTION NO: 19 The following SAS program is submitted: data work.passengers; if OrigPassengers = then OrigPassengers= 100; TransPassengers= 100; OrigPassengers= .; TotalPassengers= sum (OrigPassengers, T

statnmath.tistory.com

 

 

 

 

 

15. PDV (Program Data Vector)

 

Given the SAS data set PRICES :

 

PRICES  Prodid  price  producttype  sales  returns

K125 5.10 NETWORK 15 2

B132S 2.34 HARDWARE 300 10

R18KY2 1.29 SORFWARE 25 5

3KL8BY 6.37 HARDWARE 125 15

DY65DW 5.60 HARDWARE 45 5

DGTY23 4.55 HARDWARE 67 2

 

 

The following SAS program is submitted:

 

data hware inter cheap;

set prices(keep = producttype price);

if producttype = 'HARDWARE' then output hware;

else if producttype = 'NETWORK' then output inter;

 

if price le 5.00;  -------------→  PDV 에만 적용된다.  ★

run;

 

 

Q. How many observations does the HWARE data set contain?  (4)

K125 5.10 NETWORK 15 2

B132S 2.34 HARDWARE 300 10

R18KY2 1.29 SORFWARE 25 5

3KL8BY 6.37 HARDWARE 125 15

DY65DW 5.60 HARDWARE 45 5

DGTY23 4.55 HARDWARE 67 2

 

  • PDV는 데이터가 정리과는 과정이다. 이 과정이 마치면, 물리적으로 완성된 OUTPUT DATA가 생성된다.

 

 

출처 : https://statnmath.tistory.com/179

 

[A00-211, Crambible] SAS Q20 - PDV / output

SAS Base, A00-211 Crambible SAS 베이스 자격증 QUESTION NO: 20 Given the SAS data set PRICES: PRICES Prodid price producttype sales returns K125 5.10 NETWORK 15 2 B132S 2.34 HARDWARE 300 10 R18KY2 1.29 SOFTWARE 25 5 3KL8BY 6.37 HARDWARE 125 15 DY65DW

statnmath.tistory.com

 

 

 

16. DO 반복문에서 OUTPUT 의 유무에 따른 결과 차이

 

[OUTPUT 이 있는 경우]    Q. WORK.sales 셋에 쓰여지는 관측값 수 : 60

 

data work.sales;

  do year = 1 to 5;

  do month = 1 to 12;

  x + 1;

  output;

  end;

  end;

run;

 

  • OUTPUT 은 계산 결과를 저장한다.

 

[OUTPUT 이 있는 경우]    Q. WORK.sales 셋에 쓰여지는 관측값 수 : 1

 

data work.sales;

  do year = 1 to 5;

  do month = 1 to 12;

  x + 1;

  end;

  end;

run;

 

  • 따로 output 으로 보내는 설정이 없어서 계속 반복문이 덮어쓰이게 된다.  ★
  • 최종적으로 PDV 에는 

        year  month  X

         5       12     60   

  이렇게 저장되며 observation은 결국 1개가 된다.

 

 

 

출처 : https://statnmath.tistory.com/171 , https://statnmath.tistory.com/180

 

[A00-211, Crambible] SAS Q21 - do / while (비슷한문제 12번 참고)

SAS Base, A00-211 Crambible SAS 베이스 자격증 QUESTION NO: 21 The following SAS program is submitted: data work.sales; do year = 1 to 5; do month = 1 to 12; x+ 1; end; end; run; How many observations are written to the WORK.SALES data set? A. 0 B. 1

statnmath.tistory.com

 

 

 

 

17. Array 


[1차원 배열]

형식 : array 배열이름{차원수} 내용;

- 변수 범위 지정

  • 변수들의 이름은 마지막 문자를 제외하고 같아야 한다. (또한 연속된 숫자여야 함)
  • 마지막은 반드시 숫자
  • ex) array abc{4} a1 a2 a3 a4;  →  array abs{4} a1-a4;

- 숫자형 변수 지정

  • 현재 data 단계에 이미 정의된 모든 숫자형 변수를 지정
  • ex) array abc{*} _numeric_;

- 문자형 변수 지정

  • 현재 data 단계에 이미 정의된 모든 문자형 변수를 지정
  • ex) array abc{*} _character_;

- 전체 변수 지정

  • 모든 변수를 지정
  • ex) array abc{*} _all_;

 

[배열 참조]

형식 : 배열이름{인덱스 값};

 

(예시)

data work.conv;

   set fit;

   array wt{6} weight1-weight6;

   do i = 1 to 6;

      wt{i} = wt{i} * 2.2046;

   end;

run;

 

 

출처 : https://m.blog.naver.com/PostView.naver?isHttpsRedirect=true&blogId=hsj2864&logNo=220627714263 

 

SAS - array(배열)

배열처리 - 반복 계산 수행 - 같은 속성을 같은 많은 변수들 생성 - 데이터 읽기 - sas 데이터세트에서 변...

blog.naver.com


 

data work.totalsales  (keep = monthsales{12});

  set work.monthlysales (keep = year product sales);  -------------→ KEEP dataset option

  array monthsales{12};

  do i = 1 to 12; monthsales{i} = sales;

  end;

run;

 

Q. The program fails execution due to syntax errors. What is the cause of the syntax error?
(An array cannot be referenced on a KEEP data set option.)

  • array 는 keep option 과 같이 나올 수 없는 문법이다.

 

출처 : https://statnmath.tistory.com/181

 

[A00-211, Crambible] SAS Q22 - the syntax error

SAS Base, A00-211 Crambible SAS 베이스 자격증 QUESTION NO: 22 The following SAS program is submitted: data work.totalsales (keep = monthsales{12}); set work.monthlysales (keep = year product sales); array monthsales{12); do i = 1 to 12; monthsales{i)

statnmath.tistory.com


 

The following SAS program is submitted:

 

data work.test;

set work.staff (keep = kansales febsales marsales);     -------------→ keep 이용하여 세가지 변수를 가져온다.

array diff_sales{3} difsales1 - difsales3;  -------------→ dfsales 1,2,3 을 정의하고 있다.

array monthly{3} jansales febsales marsales;  -------------→  monthly 라는 이름의 array, 기존에 있는 것을 그대로 불러옴

run;

 

 

Q. Which new variables are created?

(difsales1, difsales2, difsales3)

 

  • diff_sales, monthly 라는 이름이 새롭게 만들어 진 것이고, 그 안에 있는 array 구성원은 위에 정의된 것처럼 불러오게 된다. (new variable이므로 답이 difsales1, difsales2, difsales3 이다.)

 

 

 

출처 : https://statnmath.tistory.com/200

 

[A00-211, Crambible] SAS Q41 - array

SAS Base, A00-211 Crambible SAS 베이스 자격증 QUESTION NO: 41 The following SAS program is submitted: data work.test; set work.staff (keep = jansales febsales marsales); array diff_sales{3} difsales1 - difsales3; array monthly{3} jansales febsales ma

statnmath.tistory.com

 

 

 

 

 

18. Like Operator (% , _ )

  • underscore (_) : matches any single character.
  • percent sign (%) : matches any sequence of zero or more characters.

Given the SAS data set EMPLOYEES : EMPLOYEES

 

NAME  SALARY

lnnis   60000    -------------→  %i

Jolli   50000    -------------→  %i

Ellis   55000    -------------→ %i_

Liu   45000    -------------→ _i%

 

The following SAS program is submitted:

 

proc print = employees;

where name like '_i%';     

run;

 

 

 

 

 

Q. What is contained in the output?  (Liu only)

  • (i 를 기준으로)  _ : 문자 & 숫자 가능, 단 개수가 하나
  • (i 를 기준으로)  % : 문자 & 숫자 가능, 개수 제한 없음

 

출처 : https://statnmath.tistory.com/182

 

[A00-211, Crambible] SAS Q23 - wild card

SAS Base, A00-211 Crambible SAS 베이스 자격증 QUESTION NO: 23 Given the SAS data set EMPLOYEES: EMPLOYEES NAME SALARY Innis 60000 Jolli 50000 Ellis 55000 Liu 45000 The following SAS program is submitted: proc print data = employees; where name like '

statnmath.tistory.com

 

 

 

 

19. WEEKDAY : 요일을 나타내는 함수

Given the SAS data set ONE:

 

Obs Dte

1 09JAN2005

2 12JAN2005

 

The following SAS program is submitted:

 

data two:

   set one:

   day = <insert expression here>;

   format dte date9.;

run;

 

The data set TWO is created:

 

Obs   Dte    Day

1   09JAN2005 1

2   12JAN2005 4

 

 

Q. Which expression syccessfully completed the program and created the variable DAY?

(weekday(dte))

  • 09JAN2005는 1이고,  12JAN2005는 4이므로 요일을 의미하는 것이다.
  • WEEKDAY(변수이름)  →  일요일 부터 1로 시작한다 !!! 
  • 일요일 1 , 수요일 4

 

출처 : https://statnmath.tistory.com/183

 

[A00-211, Crambible] SAS Q24 - WEEKDAY(변수명)

SAS Base, A00-211 Crambible SAS 베이스 자격증 QUESTION NO: 24 Given the SAS data set ONE: ONE Obs Dte 1 09JAN2005 2 12JAN2005 The following SAS program is submitted: data two; set one; day = ; format dte date9.; run; The data set TWO is created: TWO

statnmath.tistory.com

 

 

 

 

20. PROC REPORT

 : 데이터셋을 통해 무언가를 report할 때 쓰임


- SAS PROC REPORT 옵션들 -

 

  • 데이터 정의

 

data a;
 input a$ b;
 cards;
 a 1
 a 2
 a 3
 a 4
 c 5
 c 6
 b 7
 b 8
 b 9
 b 10
 ;
run;

 

  • proc report 프로시져

 

proc report data=a;
   column a; * 이 컬럼에 대한 리포트를 하겠다;
   define a/group; * 중복값을 제외하고 group으로 묶겠다 ;
run;

proc report data=a;
 column a;
 define a/across; * across 옵션은 갯수를 센다;
run;

proc report data=a;
 column b;
 define b/analysis; * b 컬럼 분석 sum을 낸다. ;
run;

proc report data=a;
 column b;
 define b/display; * 그냥 그대로 보여준다.;
run;

 

 

  • 차례 대로 각각의 proc report에 대한 결과

 

 

 

출처 : https://3months.tistory.com/175

 

SAS - proc report 의 옵션들

SAS Proc report 옵션들 /* 2017.9.20 by. 3months */ SAS Base programming 자격증 공부하다가 proc report 관련 정리를 하였습니다. proc report는 데이터셋을 통해 무언가를 report할 때 쓰이는 SAS의 프로시져입니다. 데

3months.tistory.com

출처 : https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/proc/p17i2eq9r4oh4hn14c1mb0f0xdtb.htm#p17i2eq9r4oh4hn14c1mb0f0xdtb

 

SAS Help Center

 

documentation.sas.com

 

 

(syntax)

PROC REPORT DATA = dataset_name  OPTIONS;

RUN;

 

(option)

  • WINDOW (또는 WD) : 보고서는 보고서창에 나타난다.
  • NOWINDOWS (또는 NOWD) : 출력창에 보고서 목록을 보여준다.
  • SPLIT = '*' : 변수명을 두 줄 이상으로 나눌 때의 문자(*) 를 지정한다.
  • HEADLINE : 열 제목과 제목들 사이의 간격에 밑줄 친다.
  • HEADSKIP : 열 제목 아래에 또는 HEADLINE 옵션을 사용했다면 밑줄 뒤에 빈 줄을 쓴다.

 

출처 : https://m.blog.naver.com/PostView.naver?isHttpsRedirect=true&blogId=itsmesyeon&logNo=140149350546 

 

목록과 요약보고서 생성 PROC REPORT

다양한 보고서를 단일 보고서 작성도구를 사용하여 만들기 위해선 PROC REPORT를 사용할 수 있다...

blog.naver.com


Given the SAS data set SASUSER.HOUSES:

 

Obs style bedrooms bath price  sqteet street

1  CONDO 2 1.5 80050  1200 MAIN

2 CONDO 3 2.5 79350 1300 ELM

3 CONDO 4 2.5 127150 1400 OAK

4 CONDO 2 2.0 110700 1100 FIFTH

5 TOWSTORY 4 3.0 107250 2100 SECOND

6 TOWSTORY 2 1.0 55650 1600 WEST

7 TOWSTORY 2 .0 69250 1450 NORTH

6 TOWSTORY 4 2.5 102950 2000 SOUTH

 

The following SAS program is submitted:

 

PROC REPORT data=sasuser.houses nowd headline; 

column style price;

where price it 100000;      -------------→ lt : less than

<insert DEFIINE statement here>

define price / mean width=9 format dollar12.;     -------------→ 100000보다 작은 것들의 mean(평균) 이 나온다.

title;

run;

 

 

The following output is desired:

 

style price

CONDO $79,700

TWOSTORY $62550

 

 

 

Q. Which DEFINE statement completes the program and produces the desired output?

(define style / group width=9;)

 

출처 : https://statnmath.tistory.com/184

 

[A00-211, Crambible] SAS Q25 - insert DEFINE statement

SAS Base, A00-211 Crambible SAS 베이스 자격증 QUESTION NO: 25 Read the table: Given the SAS data set SASUSER.HOUSES: Obs style bedrooms baths price sqteet street 1 CONDO 2 1.5 80050 1200 MAIN 2 CONDO 3 2.5 79350 1300 ELM 3 CONDO 4 2.5 127150 1400 OAK

statnmath.tistory.com

 

 

 

 

 

21. SORT

Given the SAS data set WORKWARDS:

 

WORK.AWARDS

FNAME POINTS MONTH

Amy 2 4

Amy 1 7

Gerard 3 3

Wang 3 3

Wang 1 12

Wang 1 8

 

 

The following SAS program is submitted:

 

PROC SORT data = work.awards;

by descending fname points;      -------------→ 내림차순은 fname 변수에만 적용된다 !!! ★

run;

 

 

output:

 

FNAME POINTS MONTH

Wang 1 12

Wang 1 8

Wang 3 3

Gerard 3 3

Amy 1 7

Amy 2 4

 

  • by descending fname points ; 에서 fname 에 대하여 내림차순 정렬 후,
  • 그 안에서의 points는 default 값인 오름차순 정렬한다.
  • PROC SORT 에서 descending 각각 지정해 주어야 함  (주의 !!!)
  •  descending 뒤에 변수를 써야 하며, 하나의 변수에만 적용된다.
  •  by 변수는 기본적으로 오름차순 정렬이며, ascending 옵션은 없다.

 

출처 https://statnmath.tistory.com/185\

 

[A00-211, Crambible] SAS Q26 - sort

SAS Base, A00-211 Crambible SAS 베이스 자격증 QUESTION NO: 26 Given the SAS data set WORKAWARDS: WORK.AWARDS FNAME POINTS MONTH Amy 2 4 Amy 1 7 Gerard 3 3 Wang 3 3 Wang 1 12 Wang 1 8 The following SAS program is submitted: proc sort data = work.award

statnmath.tistory.com

 


Given the SAS data set EMPLOYEE INFO:

EMPLOYEE_INFO

 

The following SAS program is submitted:

 

proc sort data = employee_info;

<insert BY statement here>

run;

 

 

Q. Which BY statement completes the program and sorts the data sequentially by ascending Expenes values within each ascending IDNumber value?

 

A. by Expenses IDNumber;

B. by IDNumber Expenses;

C. by ascending Expenses IDNumber;

D. by ascending IDNumber ascending Expenses;  (X)

 

 

  • IDNumber를 오름차순으로 정렬한 것 내에서 Expense를 오름차순으로 정렬
  • BY 의 정렬 defaul 값이 오름차순 (ascending 옵션은 없다.)

 

출처 : https://statnmath.tistory.com/197

 

[A00-211, Crambible] SAS Q38 - sort 26번 참고

SAS Base, A00-211 Crambible SAS 베이스 자격증 QUESTION NO: 38 Given the SAS data set EMPLOYEE INFO: EMPLOYEE_INFO The following SAS program is submitted: proc sort data = employee_info; run; Which BY statement completes the program and sorts the data

statnmath.tistory.com

 

 

 

 

 

22. @ 

The contents of the raw data file PRODUCT are listed below:

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

24613   $25,31      (공백 3칸)

 

The following SAS program is submitted:

data inventory;

infile 'product';

input idnum 5. @10 price;

run;

 

 

Q. Which one of the following is the value of the PRICE variable?   (25.31) ★

  • INPUT 문 :  변수의 이름, 자료형, 자릿수 등을 지정하기 위해 사용
  • input 을 이용하여 idnum 변수를 만드려고 한다.
  • idnum 5. : 5 자리의 변수
  • @숫자 : '숫자' 지점부터 변수에 대한 값을 불러오겠다는 명령어
  • 공백이 3칸이므로 10번째가 2이므로 답은 25.31 이다.

 

Q. 만약 공백이 4칸이면?   (missing numeric value)

  • 10번째부터 읽으므로 $ 인데,이 $는 문자이다. 하지만 price는 숫자이므로 missing value 이다.
  • input 에서 price는 숫자형 변수로 지정되없는데 price 값이 문자형이므로 missing 처리 된다.

 

출처 : https://statnmath.tistory.com/187

 

[A00-211, Crambible] SAS Q28 - @

SAS Base, A00-211 Crambible SAS 베이스 자격증 QUESTION NO: 28 The contents of the raw data file PRODUCT are listed below:--------10-------20-------30 24613 $25.31 The following SAS program is submitted: data inventory; infile'product'; input idnum 5.

statnmath.tistory.com

 

 

 

 

 

 

23. Varnum option in PROC CONTETNS

The following SAS program is submitted:

 

PROC CONTENTS data=sashelp.class varnum;

quit;

 

Q. What does the VARNUM option print?

(a list of the variables in the order they were created.)

 

 

 

  • Varnum : 변수를 작성순으로 표시 (따로 표시 안해주면 디폴트 값으로 알파벳순으로 정렬됨)
  • varnum 옵션이 들어가있으면, 조회하는 테이블에서 테이블이 포함된 변수들이 만들어진 순서를 보여준다.

 

출처 : https://statnmath.tistory.com/188

 

[A00-211, Crambible] SAS Q29 - varnum

SAS Base, A00-211 Crambible SAS 베이스 자격증 QUESTION NO: 29 The following SAS program is submitted: proc contents data = sashelp.class varnum; quit; What does the VARNUM option print? A. a list of variable names B. the total number of variables C.

statnmath.tistory.com

 

 

 

24. 대·소문자 구분

 

   data test;

     set chemists;

      if jobcode = 'Chem2';

      then description = 'Senior Chemist';

      else description = 'Unknown';

   run;

 

Q. 만약 jobcode 의 값이 chem2 라면 description 의 값은?  (Unknown)

  •  대소문자가 맞지 않기 때문에 값이 Unknown 으로 할당된다.

 

 

 

25. Input 으로 raw 데이터 한 행씩 불러오기

Given the raw data file EMPLOYEE:

----|----10----|----20----|----30

Ruth  39 11    ( 이름과 age 사이에 공백이 두 칸 있다.)

Jose  32 22

Sue  30 33

John  40 44

 

The following SAS program is submitted:

 

data test;

infile 'employee';

input employee_name $ 1-4;     -------------→ 첫번째부터 네번째까지 불러온다

if employee_name = 'Ruth' then input idnum 10-11;

else input age 7-8;

run;

 

 

 

Q. What value dose the varible IDNUM contain when the name of the employee is "Ruth" (22) ★

 

  • test 데이터를 만드려고 한다. infile 을 통해 employee 데이터를 가져온다.
  • input 으로 employee_name 이라는 변수를 정의한다. 이름이 문자형으로 ($), 첫번째부터 네번째까지 불러온다
  • 이렇게 input을 사용하면 raw 데이터를 한 행씩 불러오게 된다.

 

employee_name (변수이름)

Ruth   -------------→ 첫번째 행이 들어왔다.

 

if employee_name = 'Ruth' then input idnum 10-11;  이름이 Ruth 이므로 then 이하의 구문을 확인한다.

또 다른 input을 만났다. 즉, input 으로 idnum 이란 변수를 만드는데 그 때 10~11 자리를 불러오려고 한다.

지금 input 을 두번째 만났으니 두번째 행을 읽어야 한다.

 

 

employee_name idnum

Ruth  22

 

아직 데이터 읽는것이 끝나지 않았으니 다시 input 구문으로 올라간다.

input employee_name $ 1-4;

input 을 세번째로 보는 것이므로 raw data 의 세번째 행을 본다.

 

employee_name idnum

Ruth 22

Sue

 

if employee_name = 'Ruth' then input idnum 10-11; 으로 들어오니 Sue 가 Ruth 가 아니므로 그 다음줄을 본다.

else input age 7-8;

 

네 번째 input 을 보는 것이므로 raw 데이터의 네 번째 행을 읽는다.

 

 

[최종 Output]

 

employee_name idnum age

Ruth      22

Sue                  40

 

 

 

 

출처 : https://statnmath.tistory.com/191

 

[A00-211, Crambible] SAS Q32 - input

SAS Base, A00-211 Crambible SAS 베이스 자격증 QUESTION NO: 32 Given the raw data file EMPLOYEE: ----I----1 0---I----20---I----30 Ruth 39 11 Jose 32 22 Sue 30 33 John 40 44 The following SAS program is submitted: data test; infile'employee'; input emp

statnmath.tistory.com

 

 

 

 

 

 

26. Library

data temp.x;

   set sasuser.y;

run;

 

Q. What must be submitted prior to this SAS program for  the program to execute successfully?

( A LIBNAME statement for the libref TEMP only must be submitted.)

 

  • set 을 통해 영구 library 에 있는 y를 가져오려고 한다.
  • 이때 temp 라는 라이브러리가 사전에 정의되어야 한다.
  • SASUSER 는 SAS 안에 있는 라이브러리여서 default 로 y 라는 파일만 있으면 오류가 생기지 않는다.

 

 

출처 : https://statnmath.tistory.com/192

 

[A00-211, Crambible] SAS Q21 - library

SAS Base, A00-211 Crambible SAS 베이스 자격증 QUESTION NO: 33 following SAS program is submitted: data temp.x; set sasuser.y; run; What must be submitted prior to this SAS program for the program to execute successfully? A. A LIBNAME statement for th

statnmath.tistory.com

 

 

 

 

 

 

27. LENGTH 와 FORMAT의 효력 차이

 

The data set REALESTATE has the variable LOCALFEE with a format or 9. and a variable COUNTRYFEE with a form at or 7.;

 

The following SAS program is submitted:

 

data history;

format local fee country fee percent6.;    -------------→ 퍼센트 여섯자리로 지정

set realestate;

local fee = local fee / 100;

country fee = country fee / 100;

run;

 

 

Q. What are the formats of the variables LOCALFEE and COUNTRYFEE in the output dataset?

(LOCALFEE has format of percent6. and COUNTRYFEE has a format of percent6.)

 

 

  • REALESTATE 데이터셋에는, 9의 길이를 가지고 있는 LOCALFEE 라는 변수와, 7의 길이를 가지고 있는 COUNTRYFEE 변수가 있다.
  • format은 어디에있어도 효력이 발생하지만, length 의 경우 data 와 set 사이에 위치해야 효력이 발생한다 !! ★

 

 

출처 : https://statnmath.tistory.com/193

 

[A00-211, Crambible] SAS Q34 - format / length

SAS Base, A00-211 Crambible SAS 베이스 자격증 QUESTION NO: 34 The data set RALESTATE has the variable LOCALFEE with a format or 9. and a variable COUNTRYFEE with a format or 7.; The following SAS program is submitted: data history; format local fee c

statnmath.tistory.com

 

 

 

 

 

 

 

28. PROC FREQ option

[기본]

proc freq data=class;

tables gender * age;

run;

  • 기본적으로 빈도, 백분율, 행백분율, 컬럼백분율이 생성된다.

[list]

proc freq data=class;

tables gender * age / list;

run;

  • list 를 적용하게 되면 list 형태로 빈도, 백분율, 누적빈도, 누적 백분율이 생성된다.

[ncol]

proc freq data=class;

tables gender * age / nocol;

run;

  • 빈도, 백분율, 행백분율 (컬럼백분율이 빠진다.)

[crosslist]

proc freq data=class;

tables gender * age / crosslist;

run;

  • 리스트 형태로 보여주지만 단순 list 에서, 각 카테고리별로, 그리고 그 최종합계도 생성된다.

 

 

 

 

 

29. FORMAT - DOLLARw.d 와 comma

The value 110700 is stored in a numeric variable named SALARY.

 

Q. Which FORMAT statement displays the value as $100,700.00  in a report

(format salary dollar8.2;)

  • dollar 표시가 있어야 하므로 dollar 가 포함된 보기 중에 골라야 한다.
  • . (period) 을 기준으로 앞부분은 전체자리, 뒤 기준은 소수점 자리수를 나타낸다.
  • DOLLAR w.d  : 전체자리수 . 소수점 자리수
  • dollar, comma 도 자리를 표시한다.
  • DOLLAR w.d format  으로 comma 표현할 수 있음을 주의 !!!

 

 

출처 : https://statnmath.tistory.com/195

 

[A00-211, Crambible] SAS Q36 - format

SAS Base, A00-211 Crambible SAS 베이스 자격증 QUESTION NO: 36 The value 110700 is stored in a numeric variable named SALARY. Which FORMAT statement displays the value as $110,700.00 in a report? A. format salary comma11.2; B. format salary dollar8.2;

statnmath.tistory.com

 

 

 

 

 

 

30. produce a non-missing value

Given the raw data file TEARAMT:

 

----|----10----|----20----|----30

year quality

1901 2

1905 1

1910 6

1025 .

1941 1

 

 

The following SAS program is submitted:

 

data coins;

infile ' yearamt'

input year qiantity;

<insert statement(s) here>

run;

 

 

Q. Which statement(s) completed the program and produced a non-missing value for the variable TOTQUANTITY in the final observation of the output data set?

(totquantity + quantity)  ★

 

A. totquantity + quality;

  • totquality 라는 변수가 그 전에 정의되지 않았기 때문에 새롭게 만들고 missing value 로 지정됨.
  • 이렇게 statement 로 두 개의 변수끼리 + 로 이뤄지면, quantity 를 추가적으로 누적하게 된다. ★

 

B. totquantity = sum(totquantity + quantity) ;

  • sum 의 함수 모습은 SUM (a,b) 형태로 되어야 한다. ★
  • 참고로 sum(a,b)의 경우 missing value 를 무시해서 계산되어진다.
  • totquantity 는 그 전에 값이 지정되어 있지 않아서 missing value로 지정이 되어있다.
  • (totquantity + quantity) 의 경우 operator 에 의한 연산이 된다.따라서 sum(totquantity + quantity)  = sum(missing value) 이므로 결국 전체가 missing value 가 된다.

 

C. retain rorquantity; totquantity = totquantity + quantity;

  • 이 때, retain 에서 totquantity 의 값을 missing value로 할당하였다.
  • 그 후 + 에 대한 연산이 missing value를 처리할 수 없어 결과물은 결국 missing value 가 된다.

 

D. retain totquantity0; totquantity = totquantity + quantity;

  • retain 에서 totquantity 의 값을 0으로 할당하였다.
  • 하지만, quantity에 missing value가 있기 때문에 연산처리를 할 수 없어 missing value가 된다.
  • 결과물이 2,3,9 이런식으로 계산되다가 quantity 중간에 missing value가 들어 있어서 결국 마지막 observation은 missing value 가 된다.

 

 

출처 : https://statnmath.tistory.com/196

 

[A00-211, Crambible] SAS Q37 - 연산방법 19번 참고

SAS Base, A00-211 Crambible SAS 베이스 자격증 QUESTION NO: 37 Given the raw data file YEARAMT: ----|---10---|---20---|----30 year quantity 1901 2 1905 1 1910 6 1925 . 1941 1 The following SAS program is submitted: data coins; infile 'yearamt'; input

statnmath.tistory.com

 


Retain

데이터 단계의 수행시 SAS 각 레코드(RECORD)의 자룟값들을 읽은 후에 데이터 단계에 주어진 명령문들을 수행하며 각 매체를 하나씩 차례로 생성해 나갑니다. 이러한 데이터 단계에서 각 개체를 생성하기에 앞서 사용자가 특별히 명시를 하지 않으면, SAS는 숫자변수에는 결측값을 그리고 문자변수에는 공백으로 고정시켜 놓고 시작합니다.

그렇지만 사용자가 이와 같은 처리를 원하지 않고 어떤 변수의 값을 바로 전 단계에서의 값으로 유지시키고자 한다면 그 변수의 이름을 RETAIN 명령문으로 지정하여 프로그램을 수행시키면 됩니다. 일반적으로 SAS의 연산은 단위 개체 내의 변수에 대해서만 이루어지기 때문에 개체 간의 연산이 쉽지 않다고 할 수 있는데, RETAIN 명령문은 이와 같은 개체 간의 자룟값을 비교나 연산에서 유용하게 사용됩니다

 

RETAIN variable-1 [initial-value-1] ... ;

 

이 때 특별한 지정이 없으면 RETIAN 명령문에 지정된 변수는 숫자변수가 됩니다. 문자변수로 지정하고자 할 때는 적절한 길이의 문자형 초깃값을 지정하거나 앞절에서 설명한 LENGTH 명령문으로 문자변수의 길이를 사전에 지정해야 합니다. 변수의 초깃값을 지정하지 않으면 초깃값은 결측값이 됩니다.

 

 

출처 : https://communities.sas.com/t5/SAS-Tech-Tip/SAS-%ED%99%9C%EC%9A%A9-%EB%85%B8%ED%95%98%EC%9A%B0-LENGTH-%EB%AC%B8-RETAIN-%EB%AC%B8-ARRAY-%EB%AC%B8-%EA%B8%B0%ED%83%80-%EB%AA%85%EB%A0%B9%EB%AC%B8/ta-p/793517

 

[SAS 활용 노하우] LENGTH 문 , RETAIN 문, ARRAY 문, 기타 명령문

    1. 문자변수와 LENGTH 명령문 ​ LENGTH 명령문은 선언문으로써 SAS 데이터셋에 변수가 저장될 때 사용되는 바이트(BYTE) 수를 지정해 줍니다. LENGTH 명령문을 사용할 때 조심할 점은 LENGTH 명령문이

communities.sas.com


 

 

31. PROC FORMAT

 

The following SAS program is submitted:

 

proc format 

value score 1-50 = 'Fail'    -------------→ value 를 선언하여 score 를 새롭게 정의하고자 한다.

51 - 100 = 'Pass';  --------→ 1부터 50 까지 Fail 로 빠꿔주고, 51부터 100까지 Pass라고 포맷을 바꿔준다.

run;

 

proc report data = work.courses nowd;

column exam;

define exam / display format = score.;   -------------→ score 를 display 하려고 함.

run;

 

 

proc freq data=WORK.COURSES;

table Exam;

format Exam score.; -------------→ score를 위에 지정한 포멧을 사용하려고 하므로 . (period) 가 붙음

run;

 

 

 

Q1. The variable EXAM has s value of 50.5

    How will the EXAM variable value be displayed in the REPORT procedure output?    (50.5)

 

Q2. The variable EXAM has s value of 50.5

    How will the EXAM variable value be displayed in the FREQ procedure output?    (50.5)

 

  1. Fail
  2. Pass
  3. 50.5
  4. . (missing numeric value)

 

  • 50.5 는 정의되지 않은 형태 (Fail 에도 Pass 에도 들어가지 않음) 이므로 해당 포멧을 적용해도 값이 그대로 나온다.
  • 이렇게 형식을 만족하지 않을 때는 값 그대로 나오게 된다.  ★

출처 : https://statnmath.tistory.com/198

 

[A00-211, Crambible] SAS Q39 - proc format

SAS Base, A00-211 Crambible SAS 베이스 자격증 QUESTION NO: 39 The following SAS program is submitted: proc format value score 1 - 50 = 'Fail' 51 - 100 = 'Pass'; run; proc report data = work.courses nowd; column exam; define exam / display format = sc

statnmath.tistory.com

출처 : https://statnmath.tistory.com/249

 

[A00-211, Crambible] SAS Q90 - format

SAS Base, A00-211 Crambible SAS 베이스 자격증 QUESTION NO: 90 The following SAS program is submitted: proc format; value score 1 - 50 = 'Fail' 51 - 100 = 'Pass'; run; proc freq data=WORK.COURSES ; table Exam; format Exam score.; run; The variable Exa

statnmath.tistory.com

 

 

 

 

 

32. INFILE 문에서 MISSOVER option 의 역할

Q. What is the purpose or the MISSOVER option on the INFILE statement?

(It prevents SAS from loading a new record when the end of the current record is reached.)  ★

 

  • 현재 record가 끝난 다음에 new record를 로딩하도록 해주는 옵션
  • Missing value 가 있는 데이터를 불러올 때 MISSOVER 옵션이 없으면 missing value값이 제대로 표현되지 않고 데이터가 밀려서 들어오게 된다.
  • 이처럼 missing value 가 있는 데이터를 불러올 때 MISSOVER 옵션을 사용해야 한다.

 

출처 : https://statnmath.tistory.com/199

 

[A00-211, Crambible] SAS Q40 - missover

SAS Base, A00-211 Crambible SAS 베이스 자격증 QUESTION NO: 40 What is the purpose or the MISSOVER option on the INFILE statement? A. It prevents SAS from loading a new record when the end of the current record is reached. B. It enables SAS to scan th

statnmath.tistory.com

 

 

 

 

 

 

33. _ERROR_

 

Q. describe the SAS automatic _ERROR_ variable?

  1. The _ERROR_ variable contains the values 'TRUE' or 'FALSE'     ( X )
  2. The _ERROR_ variable maintains a count of the number of data errors.     ( X )
  3. The _ERROR_ variable can be used in expressions or calculations in the DATA step.     ( O )
  4. The _ERROR_ variable contains the number or the observation that caused the error.     ( X )

 

  • 에러가 없으면 0, 에러가 있으면 1  (TRUE , FALSE 값이 아님을 주의 !!!!)   ★
  • _ERROR_ =1 로 에러 오류 처리를 할 수 있다.
  • 예) '에러가 있으면 do 반복문을 빠져나와라'
  • The _ERROR_variable can be used in expressions in the DATA step.     ( O )

 

출처 : https://statnmath.tistory.com/201

 

[A00-211, Crambible] SAS Q42 - _ERROR_

SAS Base, A00-211 Crambible SAS 베이스 자격증 QUESTION NO 42. describes the SAS automatic _ERROR_ variable? A. The _ERROR_ variable contains the values 'TRUE' or 'FALSE.' B. The _ERROR variable maintains a count of the number of data errors. C. The _

statnmath.tistory.com

출처 : https://statnmath.tistory.com/243

 

[A00-211, Crambible] SAS Q84 - _ERROR_ 42번 참고

SAS Base, A00-211 Crambible SAS 베이스 자격증 QUESTION NO: 84 Which statement describes a characteristic of the SAS automatic variable _ERROR_? A. The _ERROR_ variable maintains a count of the number of data errors in a DATA step. B. The _ERROR_ vari

statnmath.tistory.com

 

 

 

 

 

 

 

34. Informat 에서 날짜표현

Given the following raw data record: 07Jan2005

 

Q. Which INFORMAT reads this raw data and stores it as SAS data value?   (date9.)

 

  • Informat 은 데이터를 입력할 때 그 형태를 지정해주는 역할을 한다.
  • 07Jan2005 은 9 자리수로 되어있는 날짜형식 이므로 data9. 이다.

 

출처 : https://statnmath.tistory.com/202

 

[A00-211, Crambible] SAS Q43 - informat

SAS Base, A00-211 Crambible SAS 베이스 자격증 QUESTION NO: 43 Given the following raw data record: 07Jan2005 Which INFOFRMAT reads this raw data and stores it as a SAS date value? A. dmy9. B. date9. C. ddMMMyy9. D. ddmmmyyyy9. informat은 데이터

statnmath.tistory.com

 

 

 

 

 

 

 

35. mean 함수에서 다수의 변수 표현방법


Q. Which statement correctly compute the average of four numerical values?

  1. average = mean(num1, num4);     ( X )
  2. average = mean(num1 - num4);     ( X )
  3. average = mean(of num1 - num4);     ( O )
  4. average = mean(num1 num2 num3 num4);     ( X )

 

  • mean(num1, num4) : num1과 num4 에 대한 평균
  • mean(num1 - num4) : 이때 - 를 minus 로 인식한다 !!!  ★
  • mean(of num1 - num4) : - 를 minus 로 인식하는 것을 방지하기 위해 of 사용  ★
  • mean(num1 num2 num3 num4) : comma 가 없어서 오류 발생

 

 

출처 : https://statnmath.tistory.com/203

 

[A00-211, Crambible] SAS Q44 - mean

SAS Base, A00-211 Crambible SAS 베이스 자격증 QUESTION NO: 44 Which statement correctly computes the average of four numerical values? A. average = mean(num1, num4); B. average = mean(num1 - num4); C. average = mean(of num1 - num4) D. average = mean(

statnmath.tistory.com

 

 

 

 

 

 

36. MERGE 에서 라이브러리 (달라도 되는가? 된다 !)

 

The following SAS program is submitted:

The input data files are sorted by the NAMES variable:

 

libname temp 'SAS data library';

 

data temp.sales;

merge temp.sale work.receipt;

by names;

run;

 

Q. The program fails execution because the SAS data sets on the MERGE statement are in two different libraries.   (X)

  • MERGE 에서 중요한 것은 기준변수(name) 에서 sorting이 되어있는지의 여부가 중요하지
  • library 의 출처는 중요하지 않다 !! ★

 

출처 : https://statnmath.tistory.com/204

 

[A00-211, Crambible] SAS Q45 - library

SAS Base, A00-211 Crambible SAS 베이스 자격증 QUESTION NO: 45 The following SAS program is submitted: libname temp 'SAS data library'; data temp.sales; merge temp sales work.receipt; by names; run; The input data files are sorted by the NAMES variabl

statnmath.tistory.com

 

 

 

 

 

37. INPUT type$ 1-5+1 color$;

 

Given the contents of the raw data file TYPECOLOR:

 

----|----10----|----20----|----30

Daisyyellow

 

The following SAS program is submitted:

 

data flowers;

infile 'typecolor';

input type$1-5+1 color$;   -------------→ type 는 첫번째부터 다섯번째 자리까지 할당, +1 은 color변수에 할당된다.

run;

 

 

Q. What are the values of the variables TYPE and COLOR?

type  color

daisy  ellow

  • +1 은 color변수에 할당된다. 즉, 앞에서부터 한 칸 띄우고 넣으라는 의미 (ellow)  ★

 

 

출처 : https://statnmath.tistory.com/205

 

[A00-211, Crambible] SAS Q46 - input

SAS Base, A00-211 Crambible SAS 베이스 자격증 QUESTION NO: 46 Given the contents of the raw data file TYPECOLOR: ----I----10---I----20---I----30 Daisyyellow The following SAS program is submitted: data flowers; infile 'typecolor'; input type$ 1-5+1 c

statnmath.tistory.com

 

 

 

 

 

 

38. Catalog (User-defined format)

 

Q. A user-defined format has been created using the FORMAT procedure. Where is it stored?

  1. in a SAS catalog   (O)
  2. in an external binary file   (X)
  3. in a SAS dataset  in the WORK library   (X)
  4. in a SAS dataset in a permanent SAS data library   (X)

  • 사용자 정의 포맷을 정의하면 그 해당포맷은 어디에 저장되는가?
  • SAS catalog 에 저장된다. 
  • 이 catalog 에는 format, 범위, 라벨 등 여러 정보가 들어있다.

 

출처 : https://statnmath.tistory.com/206

 

[A00-211, Crambible] SAS Q47- catalog

SAS Base, A00-211 Crambible SAS 베이스 자격증 QUESTION NO: 47 A user-defined format has been created using the FORMAT procedure. Where is it stored? A. in a SAS catalog B. in an external binary file C. in a SAS dataset in the WORK library D. in a SAS

statnmath.tistory.com

 

 

 

 

 

 

39. Select & End

 

SELECT 구문은 여러 SAS 구문 또는 구문 그룹 중의 하나를 실행한다.

SELECT <(select-expression)>;
           WHEN-1 (when-expression-1< ..., when-expression-n>) statement;
     < ... WHEN-n(when-expression-1 <..., when-expression-n>) statement;>
END;

 

 

The following SAS program is submitted:

 

data work.flights;

destination = 'cph';

select(destination);   -------------→ destination 을 비교 대상으로 선정

when('LHR') city = 'London';   -------------→ destination 에 LHR이 포함되어 있으면, city 변수를 만들어 London 값을 넣음

when('CPH') city ='Copenhagen';   -------------→ CPH가 포함되어 있으면 city 변수 안에 Copenhagen 을 넣고

otherwise city = 'Other';   -------------→  이외의 상황에는 Other 를 넣어준다.

end;

run;

 

 

Q. What is the value of the CITY variable?   (Other)

  • destination은 소문자 cph 로 들어가 있고 SELECT 문에는 CPH 로 들어가 있으므로 Other로 할당된다.

 

출처 : https://statnmath.tistory.com/207

 

[A00-211, Crambible] SAS Q48 - select & end

SAS Base, A00-211 Crambible SAS 베이스 자격증 QUESTION NO: 48 The following SAS program is submitted: data work.flights; destination = 'cph'; select(destination); when('LHR') city = 'London'; when('CPH') city = 'Copenhagen'; otherwise city = 'Other';

statnmath.tistory.com

 

 

 

 

 

 

40. ; 누락된 경우

 

The following SAS program is submitted:

 

data work.retail;

cost = '20000';

total = .10 * cost     -------------→  ; 가 빠져서 에러 발생  /  . (missing numeric value)

run;

 

Q. What is the result?

  1. The value of the variable TOTAL in the output data set is missing. An error message is written to the SAS log.   (O)
  2. The variable TOTAL in the output data set has no value. The program fails to execute due to a syntax error.   (X) 
  • 2 의 경우 아에 실행을 실패한 경우, no value = 0 Observation 이다.   

[유사문제]

The following SAS program is submitted: 

 

data work.retail;

  cost = '20000';

  total =.10 * cost;

run;

 

 

Q. What is the result?  (2000)

 

  1. 2000
  2. '2000'
  3. . (MIssing numeric value)
  4. "" (Missing character value)

 

  • The value of the variable TOTAL in the output data set is 2000. A note that conversion has taken place is written to the SAS log.
  • SAS 가 알아서 문자를 숫자형으로 바꿔 계산을 한다.
  • 단, log 파일에 자신이 숫자형으로 바뀌었다고 메시지가 뜨게 된다.

 

출처 : https://statnmath.tistory.com/210

 

[A00-211, Crambible] SAS Q51 - ;

SAS Base, A00-211 Crambible SAS 베이스 자격증 QUESTION NO: 51 The following SAS program is submitted: data work.retail; cost = '20000'; total= .10* cost run; What is the result? A. The value of the variable TOTAL in the output data set is 2000. No me

statnmath.tistory.com

출처 : https://statnmath.tistory.com/260

 

[A00-211, SAS Crambible] SAS Q148 - 문자형 숫자형 값

SAS Base, A00-211 Crambible, SAS 크램바이블 SAS 베이스 자격증, SAS 문제풀이 QUESTION NO: 148 The following SAS program is submitted: data work.retail; cost = '20000'; total = .10 * cost; run; Which one of the following is the value of the va

statnmath.tistory.com


 

41. Data _null_

 

Data_null_;

set old;

put sales 1 sales2;

run;

 

Q. Where is the output written?    (to the SAS log)

 

  • old 데이터를 이용하여 진행하고 싶은데 데이터셋으로 지정하고 싶지 않을 때
  • 결과물을 output window 에서 보는 것이 아니라 log 창으로 결과물을 보고싶을 때 사용함.

 

출처 : https://statnmath.tistory.com/211

 

[A00-211, Crambible] SAS Q52 - _null_

SAS Base, A00-211 Crambible SAS 베이스 자격증 QUESTION NO: 52 The following SAS program is submitted: Data_null_; set old; put sales 1 sales2; run; Where is the output written? A. to the SAS log B. to the SAS data set _NULL_ C. to the SAS output wind

statnmath.tistory.com

 

 

 

 

 

42. _temporary_

 

data work.test;

array items{3}_temporary_(1,2,3);  -------------→  item 이라는 이름을 가진 길이 3의 array 를 만드려고 한다.

run;

 

Q. What are the names of the variable(s) in the WORK.Test data set?  

(No variables are created because it is a temporary array.)

 

  • Item 이라는 이름을 가진 길이 3의 array 를 만드려고 한다. _temporary_ 를 이용하여 임시적으로 할당함
  • 즉, 데이터에 출력이 안됨 !!  (중간 계산 용도로 사용한다 !!)

 

 

출처 : https://statnmath.tistory.com/212

 

[A00-211, Crambible] SAS Q53 - _temporary_

SAS Base, A00-211 Crambible SAS 베이스 자격증 QUESTION NO: 53 The following SAS program is submitted: data work.test; array items{3} _temporary_; 오류입니다. 아래처럼 바꿔주세요. array items{3} _temporary_(1, 2, 3); run; What are the na

statnmath.tistory.com

 

 

 

 

 

 

43. WEEKDAY default 값

 

The following SAS program is submitted:

 

data one;

date ='04juk2005'd;

format date weekdate;

run;

 

 

Q. What output is generated?

(Obs date 1 Monday, July 4, 2005)       

 

  • Weekday defualt 값 : Monday, July 4, 2005
  • weekday3. : Mon
  • weekday6. : Monday
  • weekday17. : Monday,July4,2005
  • weekday21. : Monday, July 4, 2005

 

 

출처 : https://statnmath.tistory.com/214

 

[A00-211, Crambible] SAS Q55 - WEEKDATE

SAS Base, A00-211 Crambible SAS 베이스 자격증 QUESTION NO: 55 The following SAS program is submitted: data one; date = '04juI2005'd; format date weekdate.; run; proc print data = one; run; What output is generated? A. Obs date 1 Monday, July 4, 2005

statnmath.tistory.com

 

 

 

 

 

 

44. 비교표현식 - le


비교표현식 줄임말

eq equal  (=)
ne  not equal  (<>)
lr little  (<)
le little or equal  (<=)
gt greater  (>)
ge greater or equal  (>=)

 

비교표현식

구분 표현식 비교
크다 a gt b a > b
작다 a lt b a < b
크거나 같다 a ge b a >= b
작거나 같다 a le b a <= b
같다 a eq b a == b
같지 않다 a ne b a !== b

 

참고 : https://88240.tistory.com/493

 

비교 표현식 (gt, lt, ge, le, eq, ne)

비교 표현식 줄임말eq - equal ( = )ne - not equal ( )lt - little ( < ) le - little or equal ( )ge - greater or equal ( >= ) 비교 표현식 구분 표현식 비교 크다 a gt b a > b 작다 a lt b a < b 크거나 같다 a ge b a >= b 작거나 같

88240.tistory.com


 

The following SAS program is submitted:

 

data test;

set sasuser.employees;

if 2 le year_service le 10 then    -------------→  2 <= year_service <= 10   ★

amount = 1000;

else amount = 0;

amount_per_year = year_service / amount; 

run;

 

 

 

Q. What is the value of the variable AMOUNT_PER_YEAR if an employee has been with the company for one year?         (. (missing numeric value)

 

  • 2 <=  year_service <= 10 이면 amount 에 1000 을 할당, 그게 아니면 0 을 할당
  • 문제에서 year_service 가 1 이므로 amount = 0
  •  amount = 0 이므로 year_service / amount 을 계산할 수 없으므로 missing value 가 결과값으로 나온다.

 

 

 

출처 : https://statnmath.tistory.com/215

 

[A00-211, Crambible] SAS Q56 - IF le

SAS Base, A00-211 Crambible SAS 베이스 자격증 QUESTION NO: 56 The following SAS program is submitted: data test; set sasuser.employees; if 2 le years_service le 10 then amount = 1000; else amount = 0; amount_per_year = years_service / amount run; Wha

statnmath.tistory.com

 

 

 

 

 

45. 인수 없이 사용되는 PUT 구문 (Null PUT)

 

Given the SAS data set PERM.STUDENTS:

PERM.STUDENTS NAME AGE -------- -----

Alfred 14

Alice 13

Barbara 13

Carol 14

 

 

The following SAS program is submitted:

libname perm 'SAS data library';

data students;

set perm.students;

file 'file specifivation';

put name $ age;

< insert statement here >

run;

 

The following double-spaced file is desired as output.

Alfred  14       -------------→ 결과물을 double-spaced 파일로 지정하고 싶음.

Alice  13

Barbara  13

Carol  14

 

 

 

Q. Which statement completes the program and creates the desired file?   (PUT)

  1. put; : 한 칸씩 행을 벌려준다.
  2. put/; : 두 칸씩 행을 벌려준다. double-spaced 가 아니라 triple-spaced 가 된다.
  3. double ; : 에러 발생
  4. PUT_NULL_; : double-spaced 이긴 하지만 벌린 행에 .(period) 를 넣어준다.

 

출처 : https://statnmath.tistory.com/216

 

[A00-211, Crambible] SAS Q57 - put

SAS Base, A00-211 Crambible SAS 베이스 자격증 QUESTION NO: 57 Given the SAS data set PERM.STUDENTS: PERM.STUDENTS NAME AGE --------- ------- Alfred 14 Alice 13 Barbara 13 Carol 14 The following SAS program is submitted: libname perm 'SAS data library

statnmath.tistory.com

 

 

 

 

 

 

46. @, date9. ddmmyy9. 구분 / FORMAT 과 INFORMAT 의 차이

 

Given the contents of the raw data file EMPLOYEE:

----|----10----|----20----|----30

Alan          19/2/2004 ACCT

Rob          22/5/2004 MKTG

MaryJane          14/3/2004 EDUC

 

The following SAS program is submitted:

 

data emps;

infile 'employee';

input @1 name$ @15 date <insert INFORMAT here> @25 department$;

run;

 

 

 

Q. Which INFORMAT correctly completes the program?  (ddmmyy10.)

  1. date9.     (X)
  2. ddmmyyyy9.     (X)
  3. ddmmyy10.   (O)
  4. ddmmyyyy10.     (X)

 

  • @숫자 :  '숫자' 지점부터 변수에 대한 값을 불러오겠다는 명령어
  • input 을 이용하여 name, date, department 변수를 만들고 있음
  • @1 부터 쭉 불러서 name 에 넣고, @15부터 date로, @25 부터 department 로 넣음.
  • 이 때 Informat 을 사용 !!
  • 데이터를 불러올 시, format 을 바꿀 때 informat 을 사용한다. !! 

 

출처 :&nbsp;https://wikidocs.net/31042

 

출처 : https://statnmath.tistory.com/218

 

[A00-211, Crambible] SAS Q59 - @, informat, format

SAS Base, A00-211 Crambible SAS 베이스 자격증 QUESTION NO: 59 Given the contents of the raw data file EMPLOYEE: ----|----10----|----20----|----30Alan 19/2/2004 ACCTRob 22/5/2004 MKTGMaryJane 14/3/2004 EDUC The following SAS program is submitted: data

statnmath.tistory.com

 

 

 

 

47.  INPUT 문 에서 데이터 입력시 @@ 의 역할

 

The following SAS program is submitted:

 

data test;

infile 'file specifivation';

input name$ amount@@;    -------------→ observations 을 줄줄이 읽는 기능

run;

 

Q. Which of the following is true?

(Two @@ hold the raw data record acress iterations of the DATA step.)

 

  1.  Two @@ together are the same as one c.     (X)
  2.  Two @@ hold the data records until the bottom of the DATA step.     (X)
  3.  Two @@ hold the raw data record across iterations of the DATA step.     (O)
  4.  Two @@ are invalid syntax and will cause the program to fail to execute.     (X)

 

 

  • input 문은 기본적으로 한번에 한 줄씩 읽음.
  • @@ 를 붙이면 변수의 개수씩 잘라서 읽을 수 있음.

 

 

예를 들어 observations 이 1,2,3,4,5,6,7,8,9,10 이렇게 되어 있으면 

변수 X,Y 에 넣을 때 @@ 을 넣어줘야

X Y

1 2

3 4

5 6

.. 이런식으로 넣게 된다.

 

만약 @@ 가 없으면 1,2,3,4,5,6,7,8,9,10 를 하나의

X Y

1 2 만 읽고 나머지 3부터는 읽지 않는다.

 

따라서 @@ 는 데이터를 읽어보되 변수에 맞춰서 넣는 기능을 한다.

 

 

 

참고 : https://gaeko-security-hack.tistory.com/30

 

[SAS] input 문에서 데이터입력시 (@@의 역할)

input 문을 사용해 cards옵션으로 다음과 같이 직접 데이터를 입력하는 때에 데이터가 누락되서 데이터셋에 저장된다. 이는 input문은 기본적으로 한번에 한 줄씩 읽기 때문에 발생하는 현상이다.

gaeko-security-hack.tistory.com

 

참고 : https://statnmath.tistory.com/219

 

[A00-211, Crambible] SAS Q60 - @@

SAS Base, A00-211 Crambible SAS 베이스 자격증 QUESTION NO: 60 The following SAS program is submitted: data test; infile 'file specification'; input name $ amount@@; run; Which of the following is true? A. Two @@ together are the same as one c. B. Two

statnmath.tistory.com

 

 

 

 

 

48.

 

The following SAS program is submitted:

 

data numrecords;

infile 'file specification';

input @1 patient $15. relative $15-26@;     -------------→  relative 변수에 16~26 자리 변수

if relative = 'children' then input @54 diagnosis $15.@;

else if relative ='parents' then then input @28 doctor $15.

clinic $44-53 @54 diagnosis $15. @ -------------→ @ 를 이용해서 계속 데이터를 읽고 age 변수를 넣는다.

input age;

run;

 

 

Q. How many raw data records are read during each iteration of the DATA step execution?  (1)

  • = data step 이 실행될 때 raw 데이터가 몇 번 읽혀지는지?
  • @ 기능을 이용해서 데이터를 한 번 읽어온 후 읽어온 데이터를 여러 변수로 나눠 넣는다고 보면 된다 !!
  • 따라서 데이터가 한 번 읽어진다.

 

출처 : https://statnmath.tistory.com/221

 

[A00-211, Crambible] SAS Q62 - @

SAS Base, A00-211 Crambible SAS 베이스 자격증 QUESTION NO: 62 The following SAS program is submitted: data numrecords; infile 'file specification'; input@1 patient $15. relative $ 16-26@; if relative = 'children' then input @54 diagnosis $15. @; else

statnmath.tistory.com

 

 

 

 

 

49. car, carx, !!

 

The following SAS program is submitted: data combine;

 

prefix = '505'

middle = '6465 ';   -------------→ 숫자 뒤에 빈공간 존재 !

end = '09090';

<insert statement here>;

run;

 

 

Q. Which statement successfully completes the program so that TOTAL has a value of 505-6465-09090?        (total = carx('-',prefix,middle,end);)

 

  • middle 에 빈공간이 존재하지만 결과물은 빈공간이 없어졌다.
  • 문자열을 합치는데 사용되는 것 : cat, catx, !!

 

A.total = cat('-',prefix, middle, end);

  • cat은 그대로 연결. (결과 : -5056465 09090 )
  • 빈 공간이 없어지지 않고 그대로 다 연결된다.

 

B. total = catx('-',prefix, middle, end);

  • catx 는 공백을 없어주고 prefix, middle, end 를 - 로 연결한다.
  • 첫번째 지정이 구분자가 되어서 연결한다.
  • '-'는 연결을 해주라는 말임. 따라서 결과가 505-6465-09090 이다.

 

C. total = prefix !!'-'!! middle "!!'-'!! end;

  • !! 는 합쳐주는 기능이 있다.
  • cat 과 같은 기능을 한다.
  • middle " 이 quotation unbalanced 하다.    → 에러 발생

 

D. total = prefix !!'-'!! left(middle)!!'-'!! end;

  • left(문자열) : 전체 length의 변화 없이 문자열의 선두에 공백을 제거하여 왼쪽으로 정렬한다.
  • !! 로 합칠 때 공백을 없애는 기능이 없다 
  • 결과 :  505-6465 -0909

 

(참고)  문자끼리 합칠때는 + 를 사용할 수 없다.

        예 : EmpFName + EmpLName   ( X )

 

 

출처 : https://statnmath.tistory.com/224

 

[A00-211, Crambible] SAS Q65 - cat, catx, !!

SAS Base, A00-211 Crambible SAS 베이스 자격증 QUESTION NO: 65 The following SAS program is submitted: data combine; prefix='505'; middle='6465 '; end='09090'; ; run; Which statement successfully completes the program so that TOTAL has a value of 505-

statnmath.tistory.com

 

 

 

 

 

 

 

50. 문자형 / 숫자형 전환 error

 

Given the raw data file AMOUNT:

 

----|----10----|----20----|----30

$1,234    -------------→ $, 존재하므로 문자형 변수이다.

 

The following SAS program is submitted:

 

data test;

infile 'amount';

input@1 salary 6.;  -------------→ 첫번째부터 불러와서 6자리 salary 변수를 만들고자 함.

if_error_then description = "Problems';

else description = "No Problems";

run;

 

 

Q. What is the result?    (DESCRIPTION value : Problems)

 

  • salary 변수에 $ 표시가 없는 걸 보니 수치형 변수로 선언했는데  ★
  • amount 값을 보면 $(달러) 도 있고, 도 있어서 문자형 변수이다.
  • 문자형 변수를 숫자형 변수로 바꾸려고 하니 에러가 생긴다 !! 

 

 

출처 : https://statnmath.tistory.com/226

 

[A00-211, Crambible] SAS Q67 - error 문자형/숫자형

SAS Base, A00-211 Crambible SAS 베이스 자격증 QUESTION NO: 67 Given the raw data file AMOUNT: ----I---- 10---I----20---I----30 $1,234 The following SAS program is submitted: data test; infile'amount'; input@1 salary 6.; if_error_thendescription = 'Pr

statnmath.tistory.com

 

 

 

 

 

 

 

51. PUT @

 

Given the SAS data set PEPM.STUDENTS : PERM.STUDENTS :

 

NAME  AGE   -------------→  PUT statement

---------  -----

Alfred 14

Alice 13

Barbara 13

Carol 14

 

The following SAS program is submitted:

 

libname perm 'SAS data library';

data student;

set perm.student;

file 'file specification';

put name $15. @5 age 2.;  -------------→ name : 문자형 변수($), 15자리 할당, age : 5번째 자리부터 2자리까지 읽어오기

run;

 

 

답 : B

 

  • name 변수를 위해 문자형 변수로 15자리까지 할당해주었으나, 뒤의 @5 때문에 age 를 덮어버리게 된다.
  • 따라서 Alfr14 와 같은 형태가 나오게 된다.
  • name 이라는 변수 아래 Alfred 를 넣고,  name 은 15자리 까지 넣을 수 있는 자리확보가 되어있다.
  • age 라는 변수에는 @5, 즉 5번째 자리부터 age 값을 넣으라고 하므로  ★
  • 14라는 age 값이 강제로 5번째 자리부터 들어가게 되어서 결국 Alfr14 가 된다.

 

 

출처 : https://sinpong.tistory.com/69

 

Crambible / sas 문제 68

1. raw data file 만들 때의 변수와 관찰치 (PUT) 이 문제에서는 put name $15. @5 age2.; ** @는 들어갈 위치를 지정해주는 역할을 한다. 풀어보면문자형 변수 name을 15자리까지 할당 하고,age를 5번 째 자리부

sinpong.tistory.com

 

출처 : https://statnmath.tistory.com/227

 

[A00-211, Crambible] SAS Q68 - put @

SAS Base, A00-211 Crambible SAS 베이스 자격증 QUESTION NO: 68 Given the SAS data set PEPM.STUDENTS: PERM.STUDENTS NAME AGE --------- ------ Alfred 14 Alice 13 Barbara13 Carol 14 The following SAS program is submitted: libname perm 'SAS data library';

statnmath.tistory.com

 

 


INPUT statement 와 PUT statement 의 차이

 

  • The INPUT statement reads data
  • while The PUT statement writes data values, text strings, or both to the SAS log or to an external file.

 

출처 : https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lestmtsref/n0oaql83drile0n141pdacojq97s.htm

 

SAS Help Center

 

documentation.sas.com


  

 

 

52. Find 함수 

 

The following SAS program is submitted:

 

data combine;

country = 'Italy, Russia, ireland';

found = find(country,'i') -------------→ country 변수 안에 i 문자가 몇번째에 있는가?  

run;

 

Q. What is the value of the variable FOUND in the output data set?   (12)

 

  • find(변수, 찾고자 하는 문자) : 몇번째 자리에 그 문자가 있는지 알려줌.
  • 대소문자를 구별 !!!
  • country 변수 안에 i 문자가 몇번째에 있는가?  → 공백,대소문자 구별하여 12번째

 

출처 : https://statnmath.tistory.com/229

 

[A00-211, Crambible] SAS Q70 - find

SAS Base, A00-211 Crambible SAS 베이스 자격증 QUESTION NO: 70 The following SAS program is submitted; data combine; country = 'Italy, Russia, ireland'; found = find(country, 'i'); run; What is the value of the variable FOUND in the output data set? A

statnmath.tistory.com


The following SAS program is submitted:

 

data WORK.ONE;

Text='Australia, US, Denmark';

Pos=find(Text,'US','i',5);

run;

 

Q. What value will SAS assign to Pos?      (12)

  • find(변수, 키워드, 옵션으로 modifier, 옵션으로 starting point)
  • modifier : 검색할때 옵션을 주는 값 / starting porint : 어디서부터 찾을지
  • i : 검색과정에서 대소문자를 무시 / t : 검색 대상 문자열과 부분문자열 말미에 포함된 공백을 잘라낸다.
  • find(Text,'US','i',5) : Text 변수에서 US (대문자)  를 찾으려고 함.
  • 대소문자 구분을 없애고(i),  5번째부터 찾기 U 가 12번째에 있으므로 답은 12 !!!

 

 

 

출처 : https://statnmath.tistory.com/236

 

[A00-211, Crambible] SAS Q77 - find

SAS Base, A00-211 Crambible SAS 베이스 자격증 QUESTION NO: 77 The following SAS program is submitted: data WORK.ONE; Text='Australia, US, Denmark'; Pos=find(Text,'US','i',5); run; What value will SAS assign to Pos? A. 0 B. 1 C. 2 D. 12 work라이브

statnmath.tistory.com

 

 

 

 

 

 

 

53. PROC PRINT 문에 firstobs, obs

 

proc print data=SASHELP.CLASS(firstobs=5 obs=15);   -------------→ 5번째부터 15번째까지 가져오기

where Sex='M';

run;

 

Q. How many observations will be displayed?    (11 or fewer)

  • firstobs=숫자 : 숫자번째에서 observation을 시작하라는 뜻
  • obs=숫자 : 이 숫자번째까지 observation을 가져오라는 뜻
  • 15 - 5 + 1 =11 개에서 where 조건을 만족하지 않는 경우까지 고려하면 답은 '11 or fewer'

 

출처 : https://statnmath.tistory.com/230

 

[A00-211, Crambible] SAS Q71 - print, firstobs

SAS Base, A00-211 Crambible SAS 베이스 자격증 QUESTION NO: 71 Given the following code: proc print data=SASHELP.CLASS(firstobs=5 obs=15); where Sex='M'; run; How many observations will be displayed? A. 11 B. 15 C. 10 or fewer D. 11 or fewer proc 에

statnmath.tistory.com

 

 

 

 

 

 

54. Infile 문에서 truncover

 

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

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

daisyyellow    -------------→ 11자리

 

The following SAS program is submitted:

 

data FLOWERS;

infile 'TYPECOLOR.DAT' truncover-------------→ truncover 라는 옵션이 걸려있음

length Type $ 5 Color $ 11;

input Type $ Color $; run;

 

 

Q. What are the values of the variables Type and Color?      (Type=daisy, Color=)

 

  • type 의 길이가 5로 지정되어 있으므로 daisy 까지 들어가게 된다.
  • 하지만 truncover 옵션이 없으면 color 에서 에러가 발생하게 된다.
  • raw 데이터가 daisyyellow 만 들어가 있어서 type 를 읽은 후 color 에 읽을 데이터가 없기 때문 !! ★
  • truncover : 읽은 데이터가 없어 에러가 발생하는 것을 방지한다.
  • (다음행으로 넘어가지 말고 읽지 않도록 해준다.)
  • 따라서 type 에는 daisy만 들어있고, 그 다음 불러올 데이터가 없지만 에러는 뜨지 않고 missing value 라고만 들어가 있도록 color에는 아무런 값이 들어가지 않게 된다.

 

출처 : https://statnmath.tistory.com/232

 

[A00-211, Crambible] SAS Q73 - length input truncover

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

statnmath.tistory.com

 

 

 

 

 

 

55. raw file 읽기

 

Given the following raw data records in DATAFILE.TXT:

 

---|---10---|----20----|----30

Kim,Basketball,Golf,Tennis  

Bill,Football

Tracy,Soccer,Track

 

The following program is submitted:

 

data WORK.SPORTS_INFO;

length Fname Sport1-Sport3 $10;

infile 'DATAFILE.TXT' dlm=',';  -------------→ , 을 기준으로 데이터를 불러온다.

input Fname $ Sport1 $ Sport2 $ Sport3 $;

run;

 

proc print data=WORK.SPORTS_INFO;

run;

 

 

 

Q. Which output is correct based on the submitted program?     (C)

 

 

  • raw data에 Tennis 다음엔 , 로 구분된것이 아니라 다음행에 데이터가 있다.
  • 따라서 다음줄로 읽게 된다.
  • Bill    Football   ????
  • 또 다음 데이터가 엔터로 구분되어 있으므로 다음줄의 값이 읽혀진다. (Tracy)
  • Track 는 읽혀지지 못하게 된다.

 

 

 

출처 : https://statnmath.tistory.com/237

 

[A00-211, Crambible] SAS Q78 - read raw file

SAS Base, A00-211 Crambible SAS 베이스 자격증 QUESTION NO: 78 Given the following raw data records in DATAFILE.TXT: ----|----10---|----20---|----30 Kim,Basketball,Golf,Tennis Bill,Football Tracy,Soccer,Track The following program is submitted: data W

statnmath.tistory.com

 

 

 

 

 

56. ODS statement 문법 숙지

 

The following SAS program is submitted:

 

<insert ods code>

proc means data=SASUSER.SHOES;

where Product in ('Sandal', 'Slipper','Boot');

run;

<insert ods code>

 

Q. Which ODS Statement inserted, respectively, in the tow location above creates a report stored in an html file?     (C)

 

 

  • 결과물을 특정 포맷으로 보내고 싶을 때 ODS(Output Delivery System) 문을 사용한다.

 

 

 

 

 

57. Infile 을 통해 아래 정의된 datalines을 불러오기  ★

 

Given the following data step:

 

data WORK.GEO;

infile datalines;  -------------→ infile 을 통해 아래 정의된 datalines 을 불러오게 된다.

input City $20;

if City='Tulsa' then Sate='OK'; Region='Central';

if City='Los Angeles' then State='CA';

Region='Western';

datalines;    

Tulsa

Los Angeles

Bangor;

run;

 

 

Q. After data step execution, what will data set WORK.GEO contain?    (A) ★

 

 

1. input 을 만났으니 첫번째 Tulsa 를 읽어온다. 

 

City   State  Region

Tulsa  OK  Central  Western

 

  • if 구문에서 City 가 Tulsa가 되면 State는 OK 가 된다.
  • Region 에서 Central을 넣으라고 했음.
  • 다시 if 구문에서 Los Angeles 라고 되어 있으니 해당이 되지 않아 건너뛰고,
  • 다시 Region 에서 Western 이라고 지정하였으므로 Central 이 없어지고 Western 으로 바뀐다.

 

2. 두번째 Los Angeles 를 읽어온다.

 

City   State  Region

Tulsa  OK   Western

Los Angeles  CA  Central  Western

 

  • if 구문에서 City가 Tulsa 가 아니라서 건너뛰고 Region에서 Central을 넣는다.
  • if 구문에서 Cirt 가 Los Angeles 이므로 State는 CA 값을 가지며
  • 다시 Region 에는 Western값을 가진다.

 

3. 세번째 Bangor 를 읽어온다.

 

City   State  Region

Tulsa  OK   Western

Los Angeles  CA   Western

Bangor             Central  Western

 

  • if 구문에서 City가 Tulsa 가 아니여서 건너뛴다.
  • Region 에서 Central의 값을 가지며,
  • if 구문에서 City가 Los Angeles 이므로 또 건너뛴다.
  • Region 에서 Western의 값을 가진다.

 

따라서 최종 데이터셋은

  

City               State       Region

Tulsa               OK          Western

Los Angeles    CA          Western

Bangor                           Western

 

 

 

출처 : https://statnmath.tistory.com/241

 

[A00-211, Crambible] SAS Q82 - input

SAS Base, A00-211 Crambible SAS 베이스 자격증 QUESTION NO: 82 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';

statnmath.tistory.com

 

 

 

 

 

 

58. Microsoft Excel 에서 볼 수 있는 ODS destination

 

Q. Which of the following choices is an unacceptable ODF destination for producing output that can be viewed in Mocrpspft Excel?     (WINXP)

 

  1. MSOFFICE2K   (acceptable ODF destination)
  2. EXCELXP   (acceptable ODF destination)
  3. CSVALL   (acceptable ODF destination)
  4. WINXP   ( nacceptable ODF destination )

 

  • MSOFFICE2K, EXCELXP, CSVALL 은 모두 엑셀에서 아웃풋을 볼 수 있다.
  • WINXP 는 운영체제를 말한다.

 

 

출처 : https://statnmath.tistory.com/242

 

[A00-211, Crambible] SAS Q83 - ods

SAS Base, A00-211 Crambible SAS 베이스 자격증 QUESTION NO: 83 Which of the following choices is an unacceptable ODS destination for producing output that can be viewed in Microsoft Excel? A. MSOFFICE2K B. EXCELXP C. CSVALL D. WINXP A, B, C는 모두

statnmath.tistory.com

 

 

 

 

 

59. Excel Worksheet 불러오기

 

The Excel workbook REGION.XLS contains the following 4 worksheets:

 

EAST  WEST NORTH  SOUTH

 

The following program is submitted:

 

libname  MYXLS  'region.xls';   -------------→ 파일을 MYXLS로 라이브러리 설정

 

 

Q. Which PROC PRINT step correctly displays the NORTH worksheet?

(proc print data=MYXLS.'NORTH$'n; run;)   ★

 

  1. proc print data=MYXLS.NORTH; run;     (X)
  2. proc print data=MYXLS.NORTH$; run;     (X)
  3. proc print data=MYXLS.'NORTH'e; run;     (X)
  4. proc print data=MYXLS.'NORTH$'n; run;     (O)
  • 엑셀파일에 4개의 워크시트가 있다.
  • 파일을 MYXLS로 라이브러리 설정, 엑셀 파일안에 있는 워크시트들이 SAS 데이터로 인식된다.
  • proc print data=MYXLS.'NORTH$'n; run;   (문법 암기 !!!!)

 

출처 : https://statnmath.tistory.com/244

 

[A00-211, Crambible] SAS Q85 - Excel workbook

SAS Base, A00-211 Crambible SAS 베이스 자격증 QUESTION NO: 85 The Excel workbook REGIONS.XLS contains the following four worksheets: EAST WEST NORTH SOUTH The following program is submitted: libname MYXLS 'regions.xls'; Which PROC PRINT step correctl

statnmath.tistory.com

 

 

 

 

 

 

60. Where, like , % 로 원하는 데이터만 추출하기

 

Given the data set WORK.EMPDATA:

 

 

Q. Which one of the following where statements would display observations with job titles containing the word 'Manager'?       (Where Job_Title like '%Manager%';)

 

 

1. Where substr(Job_Title,(length(Job_Title)-6))='Manager';       

  • 'Administration Manager' 의 단어길이 21.
  • 일단 Job_Title 의 변수 길이는 21은 되어야 한다. (21보다 짧으면 길이가 짤림)   ★
  • (변수 길이 먼저 생각해보기 !!!) 
  • length(Job_Title)-6 은 21 - 6 이므로 15이다.  ★
  • Where substr(Job_Title, 15) : Job_Title 에서 15번째부터 값을 가져오기
  • 예를 들어 'Director' 의 경우 15보다 작기 때문에 15번째부터 값을 가져와야 하므로 공백값을 가진다.
  • 'Sales Manager'의 경우 역시 15번째 부터 가져와야 하므로 공백을 가진다.

 

2. Where upcase(scan(Job_Title,-1,' '))='MANAGER'     

  • scan(Job_Title,-1,' ') : Job_Title 변수를 공백으로 구분했을 때, 뒤에서 첫번째 덩어리 가져오기
  • 'Director' 의 경우 변수를 공백으로 구분하면 한 덩어리가 된다.
  • 뒤에서 첫번째꺼를 가져오므로 결국 Director 가 된다.
  • 'Sales Manager' 의 경우 공백으로 구분하면 두 덩어리가 되었으므로 뒤에서 첫번째인 Manager 가된다.
  • 'Sales Manager II' 의 경우 공백으로 구분하면 세 덩어리이며, 뒤에서 첫번째인 II 값을 가진다.
  • upcase : 소문자를 대문자로 바꿔주는 역할

 

3. Where Job_Title='%Manager '; 

  • % : 와일드카드 , 어떤 문자의 앞 혹은 뒤에 어떤 문자가 와도 괜찮다는 의미.
  • '%Manager ' : Manager 앞에 아무거나 와도 상관이없음. 대신 뒤에 공백이 있어야 함.

 

 

4. Where Job_Title like '%Manager%'   (O)

 

 

출처 : https://statnmath.tistory.com/245

 

[A00-211, Crambible] SAS Q86 - where, %

SAS Base, A00-211 Crambible SAS 베이스 자격증 QUESTION NO: 86 Given the data set WORK.EMPDATA: Employee_ Manager_ID Job_Title Department ID (4개 변수) 120101 Director Sales Management 120261 120102 Sales Manager Sales Management 120101 120103 Sale

statnmath.tistory.com

 

 

 

 

 

 

61. "01Jan1960"(공백)D;

 

The following SAS program is submitted:

 

data WORK.DATE_INFO;

X="01JAN1960" D  -------------→ D 앞뒤로 공백이 있다. / D : 1960년 1월 1일 기준 날자 차이를 의미

run;

 

Q. What variable X contains what value?

(the code contains a syntax error and does not execute.)

 

  1. the numeric value 0    (X)
  2. the character value "01Jan1960"    (X)
  3. the data value 01011960    (X)
  4. the code contains a syntax error and does not execute.    (O)

 

  • D의 앞뒤로 공백이 없어야 한다.
  • 만약 공백이 없으면 값이 0 이다. (1960년 1월 1일 이 0 이기 때문.)
  • D 의 의미 : 1960.01.01 기준으로 며칠의 차이가 있는 건지 숫자로 결과값을 나타내라는 의미   
  • 만약 "02Jan1960"D 라면 1960.1.1 이 0 이고 2일이면 차이가 1이므로 X 값이 1 이된다.  

 

출처 : https://statnmath.tistory.com/246

 

[A00-211, Crambible] SAS Q87 - date

SAS Base, A00-211 Crambible SAS 베이스 자격증 QUESTION NO: 87 The following SAS program is submitted: data WORK.DATE_INFO; X="01Jan1960" D ; run; What variable X contains what value? A. the numeric value 0 B. the character value "01Jan1960" C. the da

statnmath.tistory.com

 

 

 

 

 

 

62. MERGE

Given the SAS data set WORK.EMP_NAME:

 

Name   EmpID

Jill  1864

Jack  2121

Joan 4698

John  5463

 

Given the SAS data set WORK.EMP_DEPT:

 

EmpID  Department

2121 Accounting

3567 Finance

4698  Marketing

5463  Accounting

 

The following profram is submitted:

 

data WORK.ALL;

merge WORK.EMP_NAME(in=Emp_N)  WORK.EMP(in=EMP_D);  -----------→ WORK.EMP_NAME 기준으로 merge함

by Empid;

if (Emp_N and not Emp_D) or (Emp_D and not Emp_N);

run;

 

 

Q. How many observations are in data set WORK.ALL after submitting the program?   (2)

 

 

merge WORK.EMP_NAME(in=Emp_N)  WORK.EMP(in=EMP_D); 

by Empid;   

 

 

  • (in=Emp_N)  과 (in=Emp_D) 의 역할 : 데이터를 합칠 때 어떤 데이터가 어디에서 왔는지 구분하기 위함. PDV에만 생성되고 output 에는 보이지 않는다.
  • Emp_N and not Emp_D : Emp_N = 1 그리고 Emp_D =0
  • Emp_D and not Emp_N : Emp_D = 1 그리고 Emp_N =0
  • 다시말해, merged 된 데이터의 각 observation 에서 기존 두 데이터에서 각각의 observation이 missing value없이 잘 합쳐진 것이 아닌, 한쪽 데이터에는 있고 다른쪽 데이터에는 없는 것을 찾으라는 의미이다.
  • Name, EmpID 는 있지만 Department 가 없는 경우 + EmpID, Department 는 있지만 Name이 없는 경우

 

 

출처 : https://statnmath.tistory.com/247

 

[A00-211, Crambible] SAS Q88 - merge

SAS Base, A00-211 Crambible SAS 베이스 자격증 QUESTION NO: 88 Given the SAS data set WORK.EMP_NAME: Name EmpID Jill 1864 Jack 2121 Joan 4698 John 5463 Given the SAS data set WORK.EMP_DEPT: EmpID Department 2121 Accounting 3567 Finance 4698 Marketing

statnmath.tistory.com

 

 

 

 

 

63. PROC CONTETNS data=_all_;

 

The following program is submitted:

 

proc contetns data=_all_;

run;

 

Q. Which statement best describes the output from the submitted program?

(The output contains a list of the SAS data sets that are contained in the WORK library and displays the contents of those data sets.)

 

  1. The output contains only a list of the SAS data sets that are contained in the WORK library.
  2. The output displays only the contents of the SAS data sets that are contained in the WORK library.
  3. The output displays only the variables in the SAS data sets that are contained in the WORK library.
  4. The output contains a list of the SAS data sets are contained in the WORK library and displays the contents of thoese data sets.  (O)
  • _all_ 이라고 지정할 경우, default 값으로 되어있는 work 라이브러리에 있는 모든 데이터를 보여준다.
  • (WORK 라이브러리에 있는) A list of SAS data sets + the contents of those data sets

 

출처 : https://statnmath.tistory.com/248

 

[A00-211, Crambible] SAS Q89 - _all_

SAS Base, A00-211 Crambible SAS 베이스 자격증 QUESTION NO 89 The following program is submitted: proc contents data=_all_; run; Which statement best describes the output from the submitted program? A. The output contains only a list of the SAS data s

statnmath.tistory.com

 

 

 

 

 

64. PROC SORT data= ~ ; BY문에서  Descending은 변수앞에 지정

 

The following program is submitted:

 

proc sort data=SASUSER.PROJECTS out=PSORT;

by Code descending Date Cost;   -------------→  Code 는 오름차순, Date는 내림차순, Cost는 오름차순 정렬

run;

 

 

Q. Which of the following is true concerning the submitted program?

(The variable Code is sorted by ascending order.)

 

 

  • 정렬할 때 아무런 값이 없으면 default 로 오름차순 
  • 내림차순 정렬하고 싶으면 변수 앞에 descending 지정

출처 : https://statnmath.tistory.com/250

 

[A00-211, Crambible] SAS Q91 - sort by

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 de

statnmath.tistory.com

 

 

 

 

 

 

65. PROC MEANS 옵션 (maxdes=1)

- proc means option -

data=sas data set 분석할 sas 데이터셋을 지정
noprint proc means 결과를 출력창으로 출력하지 않는다.
즉, 출력창에 출력하지 않고 새로운 데이터셋을 만드는 경우 사용
maxdec=n 출력되는 통계량의 소수점 자리수를 지정한다.
(0부터 8자리까지 가능)
fw=n 통계량 출력시 field width 를 지정한다.
missing 결측치를 분류변수인 class에 대해서는 유효한 값으로 처리한다.
order=freq 분류변수인 class 변수값의 순위를 도수크기에 따라 출력한다.
order=data 데이터셋에서 만나는 순서에 따라 class 변수의 출력 순서를 결정한다.

 

 

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:

 

 

Q. Which statement below was modified or added to generate the results above:

(proc means data=SASHELP.CLASS min max mean maxdec=1;) 

 

  • maxdec = 1 : 소수점 한자리까지 나타냄  (max decimal)

 

출처 : https://www.sasbigdata.com/entry/SAS-SAS-proc-means

 

[SAS] SAS proc means

sas에서 가장 많이 사용하는 구문중에 하나가 proc means이다. 자주 사용하는 구문이지만 할 때 마다 헷갈리고, 많은 기능들이 있는데 모두 활용하지 못하는 경우가 대부분이다. proc means에 대해서

www.sasbigdata.com

출처 : https://statnmath.tistory.com/251

 

[A00-211, Crambible] SAS Q92 - format

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

statnmath.tistory.com

 

 

 

 

 

 

 

66. DO 반복문 결과 몇 개의 observation 이 생성되는지 숙지  ★

 

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;    -----------→ year 변수 생성

set banks;

capital + 5000;  -----------→ capital 이라는 변수 생성   (총 4개의 변수가 된다.)

end;  -----------→ DO 반복문에서 output 이 없으므로 결과물을 내보내지 않고 덮어씌우게 된다. ★

run;

 

 

Q. Which one of the following represents how many observations and variables will exist in the SAS data set NEWBANK?       (1 observations and 4 variables)

 

 

출처 : https://statnmath.tistory.com/254

 

[A00-211, SAS Crambible] SAS Q141 - do 반복문

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 submi

statnmath.tistory.com

 

 

 

 

 

 

 

67. DO WHILE , DO UNTIL 비교

 

The following SAS program is submitted:

 

data work.clients;

calls = 6;

do while (calls le 6);

calls + 1;

end;

run;

 

Q. Which one of the following is the value of the variable CALLS in the output data set?    (7)

 

 

  • calls 의 값이 6으로 할당된 것으로 시작하여 반복문에 들어와 7이 되었고 
  • 이 값이 do while (calls le 6 : less than or equal 6) 의 조건을 만족하지 않아 7이 결과값으로 나왔음.

 

Q. DO UNIL 을 사용하여 같은 결과값 얻기  (do until (call ge 6))

  • 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 반복문 아래에서 조건값을 확인한다.
  • ge : greater or equal to

 

 

출처 : https://statnmath.tistory.com/255

 

[A00-211, SAS Crambible] SAS Q142 - do while, do until 비교!!!

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 v

statnmath.tistory.com

 


The following SAS program is submitted:

 

data work.pieces;

 

do while (n lt 6);

n+1;

end;

run;

 

Q. Which one of the following is the value of the variable N in the output data set?   (6)

 

출처 : https://statnmath.tistory.com/256

 

[A00-211, SAS Crambible] SAS Q143 - do while (142번 참고)

SAS Base, A00-211 Crambible, SAS 크램바이블SAS 베이스 자격증, SAS 문제풀이 QUESTINO: 143 The following SAS program is submitted: data work.pieces; do while (n lt 6); n + 1; end; run; Which one of the following is the value of the variable N

statnmath.tistory.com

 

 

 

 

 

68. ddmmyy10.과 yymmdd10. 

 

A raw data record is listed below:

 

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

1999/10/25    -----------→ 데이터가 year 로 시작함 !! ★

 

The following SAS program is submitted:

 

data projectduration;

infile 'file=specification';

input data $ 1-10;

run;

 

Q. Which one of the following statements completes the program above and computes the duration of the project in days as of today's date?     (duration = today() - input(date,yymmdd10.);)

 

  • PUT : 수치값 → 문자값
  • INPUT : 문자값  수치값
  • input 중에서 date 형식이 ddmmyy 인지 , yymmdd 인지 확인해보면 데이터가 year (1999) 로 시작하므로 yymmdd 형식이다 !!! ★
  • 날짜형식 무조건 ddmmyy 아님을 주의 !!! ★

 

출처 : https://statnmath.tistory.com/257

 

[A00-211, SAS Crambible] SAS Q144 - put / input / date

SAS Base, A00-211 Crambible, SAS 크램바이블SAS 베이스 자격증, SAS 문제풀이 QUESTION NO: 144 A raw data record is listed below: --------10-------20-------30 1999/10/25 The following SAS program is submitted: data projectduration; infile 'file

statnmath.tistory.com

 

 

 

 

 

 

69. 두 변수를 더하는 방법 

The following SAS program is submitted:

 

data work.products;

Product_Number = 5461;

Item = '1001;

Item_Reference = Item'/'Product_Number;

run;

 

Q. Which one of the following is the value of the variable ITEM_REFERENCE in the output data set?

(The value can not be determined as the program fails to execute due to errors.)

 

  1. 1002/5461
  2. 1001/5461
  3. . (missing numeric value)
  4. The value can not be determined as the program fails to execute due to errors.  (O)

 

  • Item = '1001; 에서 따옴표 때문에 결과값이 아무것도 나오지 않는다.
  • Q. 만약 1001/5461 로 넣고 싶다면?
  • Item ||'/'|| Product_Number

 

 

출처 : https://statnmath.tistory.com/259

 

[A00-211, SAS Crambible] SAS Q147

SAS Base, A00-211 Crambible, SAS 크램바이블SAS 베이스 자격증, SAS 문제풀이 QUESTION NO: 147 The following SAS program is submitted: data work.products; Product_Number = 5461; Item = '1001'; Item_Reference = Item'/'Product_Number; run; Which

statnmath.tistory.com

 

 

 

 

 

 

 

70. SCAN , SUBSTR , Scan 의 함수 길이를 지정하지 않았을 때 변수의 length

 

The following SAS program is submitted:

 

data work.test;

Author = 'Agatha Christie';

First = substr(scan(author,1,','),1,1);    -----------→ SCAN 함수 길이가 지정되지 않음 ★

run;

 

 

Q.  Which one of the following is the length of the variable FIRST in the output data set?  (15) 

 

  1. 1
  2. 6
  3. 15
  4. 200

 

  • SAS 9.4 버전에서는 답이 200이 맞지만 버전이 바뀐 뒤로는 15가 답이다.
  • scan 함수의 길이가 따로 지정되지 않으면 첫번째 값 (Argument) 이 길이로 지정된다.   ★
  • LENTH 문 : If this option is not used, the default length for character variables is 200.

 

- SCAN (변수, 몇번째, '구분자') -

  • 구분자는 기본값으로 빈칸, 콤마가 되어있기 때문에 생략하여 SCAN(변수, 순서) 로 사용 할 수도 있다.

- SUBSTR (변수, 시작할 col 좌표, 읽을 글자의 개수) -

  • 이름 값이 '홍 길동' 이라면 substr(이름,1,3) 의 값은 '홍 길' 이다.

 

출처 :&nbsp;https://communities.sas.com/t5/SAS-Tech-Tip/SAS-%ED%99%9C%EC%9A%A9-FAQ-%ED%95%A8%EC%88%98-%EB%AC%B8%EC%9E%90%ED%95%A8%EC%88%98/ta-p/779286

 

출처 : https://documentation.sas.com/doc/en/sclref/9.4/n05sotxgrg1itjn19v8xpxg613z1.htm

 

SAS Help Center: LENGTH (declaration)

In SCL, LENGTH is a declarative statement and can be used only to set the lengths of nonwindow variables. If you attempt to specify a length for a window variable, a compile error occurs. You typically place LENGTH statements at the beginning of a program,

documentation.sas.com

출처 : https://statnmath.tistory.com/261

 

[A00-211, SAS Crambible] SAS Q149 - length

SAS Base, A00-211 Crambible, SAS 크램바이블 SAS 베이스 자격증, SAS 문제풀이 QUESTION NO: 149 The following SAS program is submitted: data work.test; Author = 'Agatha Christie'; First = substr(scan(author,1,' ,'),1,1); run; Which one of the f

statnmath.tistory.com


The following SAS program is submitted:

 

data work.test;

Author = 'Christie, Agatha';

First = substr(scan(author,2,' ,'),1,1)-----------→ '공백,'

run;

 

Q. Which one of the following is the value of the variable FIRST in the output data set?   (A)

 

 

 

  • scan(author,2,' ,') : 공백과 콤마를 구분자로 하여 두번째 단어를 읽는다.  (Agatha)
  • substr(scan(author,2,' ,'),1,1) : 첫번째부터 1개만 뽑아내면 'A' 가 추출된다.

 

출처 : https://m.blog.naver.com/PostView.naver?isHttpsRedirect=true&blogId=iiamhappy&logNo=221237695817 

 

SAS BASE :: 덤프문제(crambible) Q.141~Q.160中

QUESTION NO: 141 The SAS data set BANKS is&nbs...

blog.naver.com

출처 : https://statnmath.tistory.com/263

 

[A00-211, SAS Crambible] SAS Q152, 153 substr

SAS Base, A00-211 Crambible,SAS 크램바이블 SAS 베이스 자격증, SAS 문제풀이 QUESTION NO: 152 The following SAS program is submitted: data work.test; First = 'Ipswich, England'; City_Country = substr(First,1,7)!!', '!!'England'; run; Which one

statnmath.tistory.com

 


 

The following SAS program is submitted:

 

data work.test;

First ='Ipswich, England';

City_Country =substr(First,1,7)!!', '!!'England';   -----------→  || , !! : 문자와 문자를 연결해주는 역할

run;

 

 

Q.Which one of the following is the length of the variable CITY_COUNTRY in the output data set? 

     (25) ★

 

 

  • Substr 함수 사용시 사전에 LENGTH 로 길이를 지정해주지 않았기 때문에 First는 첫번째 argument의 length 값을 갖는다. 
  • 따라서 Ipswich, England [16] + ,(공백) [2] + England [7] = 25

 

  • "In a DATA step, if the SUBSTR (right of =) function returns a value to a variable that has not previously been assigned a length, then that variable is given the length of the first argument.
  • Meaning that substr(First,1,7) has the length 16, ', ' has the length 2 and 'England' has the length 7 giving the variable City_Country a total length of 25. 

 

 

참고 : (25 이유 해설) https://communities.sas.com/t5/SAS-Programming/length-of-the-output-of-the-substr-function/td-p/436085

 

length of the output of the substr function

  Hello,   I'm preparing the sas base certification but there is a point that I don't understand   The question is to give the length of City_Country after the following program is submitted:   data work.test; First = 'Ipswich, England'; City_Country =

communities.sas.com

 

참고 : (SUBSTR)  https://documentation.sas.com/doc/da/pgmsascdc/9.4_3.2/lefunctionsref/n0n08xougp40i5n1xw7njpcy0a2b.htm

 

SAS Help Center

 

documentation.sas.com

참고 : https://statnmath.tistory.com/263

 

[A00-211, SAS Crambible] SAS Q152, 153 substr

SAS Base, A00-211 Crambible,SAS 크램바이블 SAS 베이스 자격증, SAS 문제풀이 QUESTION NO: 152 The following SAS program is submitted: data work.test; First = 'Ipswich, England'; City_Country = substr(First,1,7)!!', '!!'England'; run; Which one

statnmath.tistory.com


 

The following SAS program is submitted:

 

data work.test;

First ='Ipswich, England';

City = substr(First,1,7);     -----------→ City 변수와 First 변수의 길이 16으로 같다 !!

City_Country = Cirty!!', '!!England';

run;

 

 

Q. Which one of the following is the value of the variable CITY_COUNTRY in the output data set?

(Ipswich , England)  ★

 

  1. Ipswich!!    (X)
  2. Ipswich, England    (X)
  3. Ipswich, 'England'    (X)
  4. Ipswich , England    (O)

 

  • City 의 값은 Ipswich________(뒤에는 공백 9칸) 
  • 그리고 쉼표로 구분되어지고 다시 England 가 붙는다.
  • City_Country = Ipswic(공백 9칸) , England
  • 변수의 LENGTH 를 먼저 고려해야 함을 주의 !!!   ★
  • City 변수의 LENGTH 를 고려해야 한다. !!! ★

 

 

Q. 만약 Ipswich, England결과값을 얻고 싶으면 TRIM 기능을 이용해야 한다.

  • Citry_Country = TRIM(City)!!', '!!'England'  
  • Citry_Country = Ipswich, England 

 

출처 : https://statnmath.tistory.com/263

 

[A00-211, SAS Crambible] SAS Q152, 153 substr

SAS Base, A00-211 Crambible,SAS 크램바이블 SAS 베이스 자격증, SAS 문제풀이 QUESTION NO: 152 The following SAS program is submitted: data work.test; First = 'Ipswich, England'; City_Country = substr(First,1,7)!!', '!!'England'; run; Which one

statnmath.tistory.com

 

 

 

 

 

 

71. "날짜"d 의 Type

The following SAS program is submitted:

 

data WORK.DATE_INFO;

   X='04jul2005'd-----------→  1960.01.01 을 기준으로 며칠이나 떨어져 있는지 숫자값을 가진다.

   DayOfMonth = day(x);

   MonthOfYear = month(x);

   Year=year(x);

run;

 

 

Q. What type of variables are DayOfMonth, MonthOfYear,Year?

   (DayOfMonth, MonthOfYear,Year are numeric)

 

  1. DayOfMonth, MonthOfYear,Year are character.
  2. DayOfMonth, MonthOfYear,Year are numeric     (O)
  3. DayOfMonth,Year are numeric. MonthOfYear is character.
  4. DayOfMonth, MonthOfYear,Year are date values.

 

  • 04jul2005'd : 1960.01.01 을 기준으로 며칠이나 떨어져있는지 숫자값을 내뱉는다.
  • 따라서 X 의 Type은 Numeric 이다.
  • (날짜 뒤에 d를 붙였기 때문에 날짜가 숫자형으로 인식된다.)
  • 숫자형을 활용하여 만든 함수의 결과물도 Numeric 이다 !!   ★

 

 

 

 

 

72. SAS automatic variable _ERROR_

 

Q. Which statement is true concerning the SAS automatic variable _ERROR_?

   (It is automatically dropped.)

 

  1. It cannot be used in an if/then condition.   (X)
  2. It cannot be used in an assignment statement.   (X)
  3. It can be put into a keep statement or keep=option.   (X)
  4. It is automatically dropped.      (O)

 

  • It cannot be used in an assignment statement.   (X)
  • 만약 T 라는 변수에 _ERROR_ 값을 넣고 싶다면 T = _ERROR_ 로 할당할 수 있다.
  • It is automatically dropped.  : PDV 상에만 존재, output 에는 영향을 주지 않는다.

 

 

 

 

 

73. May, June,July 값을 갖는 변수를 내림차순 정렬한다면?

 

Given the SAS data set WORK.TEMPS :

 

Day  Month  Temp

 

1 May 75

15 May 70

15 June 80

3 June 76

2 July 85

14 July 89

 

The following program is submitted:

 

proc sort data=WORK.TEMPS;

  by descending Month Day;    -----------→  Month 에 대해 내림차순, Day 에 대해 오름차순 정렬

run;

 

proc print data=WORK.TEMPS;

run;

 

  • 내림차순이라해서 Month 값이 7,6,5 월로 정렬되는 것이 아니라 무조건 알파벳 순으로 정렬된다 !!! 

 

Q. Which output is correct?

 

Obs Day Month Temp

1 1 May 75

2 15 May 70

3 3 June 76

4 15 June 80

5 2 July 85

6 14 July 89

 

 

 

 

 

 

74. LABEL 문

The following SAS program is submitted:

 

data WORK.ACCOUNTING;

  set WORK.DEPARTMENT;

  label Jobcode='Job Description';

run;

 

 

Q. Which statement is ture about the output dataset?

   (The label of the variable Jobcode is Job Description.)

 

  1. The label of the variable Jobcode is Job (Only the first word).   (X)
  2. The label of the variable Jobcode is Job Des (Only the first 8 characters).   (X)
  3. The label of the variable Jobcode is Job Description.   (O)
  4. The program is fails to execute due to errors. Labels must be defined in a PROC step.   (X)

 

  • label 은 길이가 256인 글자까지 수용할 수 있다 !!! 
  • Label 은 PROC step 과 DATA step 모두에서 사용할 수 있다.

 

 

 

 

 

 

75. 워크시트가 있는 Excel Workbook 라이브러리 할당

 

The Excel workbook QTR1.XLS contains the following three worksheets : JAN FEB MAR

 

 

Q. Which statement correctly assigns a library reference to the Excel workbook?

  (libname qtrdata 'qtr1.xls';)

 

  1. libname qtrdata 'qtr1.xls';    (O)
  2. libname  'qtr1.xls' sheets=3;
  3. libname jan feb mar  'qtr1.xls';
  4. libname mydata  'qtr1.xls' WORK.sheets=(jan,feb,mar);

 

  • 엑셀파일 개체를 경로에 지정해주면 라이브러리로 할당한 qtrdata에 worksheets가 데이터세트로 잡혀있다.
  • 3개의 워크시트가 자동적으로 SAS data set 형태로 잡혀있다 !!!

 

 

 

 

 

 

76. CSVALL

 

The following SAS program is submitted:

 

ods csvall file='c:\test.csv';   -----------→  아래 proc print 결과를 CSV 파일로 내보낸다.

 

proc print data=WORK.ONE;   

   var Name Score Grade;

   by IdNumber;

run;

 

ods csvall close;

 

 

 

Q. What is produced as output?

   (A text file named test.csv that can be opened in Excel or in any text editor.)

 

  1. A text file named test.csv that can only be opened in Excel.
  2. A text file named test.csvthat can be opened in Excel or in any text editor.      (O)
  3. A text file named test.csv that can only be opened in a text editor.
  4. A text file named test.csv that can be opened by SAS.

 

 

 

 

 

 

 

77. ERROR 해석 - Invalid data

 

NOTE : Invalid data for Salary in line 4 15-23.

 

RULE: ----+----1----+----2----+----3----+----4----+----5---

4 120104 F 46#30 1MAY1954 33

 

Employee_Id=120104 employee_gender=F Salary=. birth_data=-2061 _ERROR_=1 _N_=4  -----------→  PDV 

(출력의 중간과정)

 

NOTE: 20 records were read from the infile 'c:/employees.dat'.

 

The minimum record length was 33.

The maximum record length was 33.

 

 

NOTE: The data set WORK.EMPLOYEES has 20 observations and 4 variables.

 

 

Q. What does it mean?

  (An execution error, triggered by an invalid character for the variable Salary.)

 

  1. A compiler error, triggered by an invalid character for the variable Salary.
  2. An execution error, triggered by an invalid character for the variable Salary.
  3. The 1st of potentially many error, this one occurring on the 4th observation.
  4. An error on the INPUT statement specification for reading the variable Salary.