SAS Advanced programming 정리- SAS programming (18)

Hoya Jaeho Lee·2022년 7월 21일
0

SAS Advanced programming

목록 보기
16/17

Modifying All Observations in a SAS Data Set

proc print data=capacity (obs=4);
run;

data capacity;
modify capacity;
CapEcon = int(CapEcon .95);
CapBusiness = int(CapBusiness
.90);
run;

proc print data=capacity (obs=4);
run;

Modifying Observations Using a Transaction Data

proc print data=capacity(obs=5);
run;

data capacity;
modify capacity sasuser.newrtnum;
by flightid;
run;

proc print data=capacity(obs=5);
run;

modify capacity sasuser.newrtnum;
구문에서 capacity가 master 데이터 셋
sasuser.newrtnum가 transaction 데이터 셋
master data set is updated by matching values of the variable FlightID!!

Route ID가 transaction data set에 존재하는 flightID에 해당하는 값으로 바뀌어서 modify됨을 확인!!

Duplicate의 경우

Transaction에서 duplicate의 값이 있는 경우 마지막 값을 master 데이터 셋에 update해 줌

Modifying Observations Located by an Index


cargo99가 master data고 sasuser.newcgnum이 transaction
newcgnum의 세 variables들 값들로 master data set 업데이트 됨
key=변수이름, index 지정 옵션 (by 와 다르게 진행됨)
key=a 로 지정하였으나, 양쪽에 매칭이 되지 않는 경우에는 error 발생!!!

이러한 경우에는 /unique 옵션을 사용해서 error를 막을 수 있음:)

MODIFY SAS-data-set KEY=index-name /UNIQUE;

Understanding Integrity Constraints


Primary key: assigning the NOT NULL and UNIQUE constraints

Placing Integrity Constraints on a Data Set


primary key와 check의 사용!! (문법 잘 확인)
check(where=~~) 이런 형식
• The PRIMARY KEY constraint is placed on the RouteID variable. This constraint
ensures that when values of RouteID are updated, they must be unique and nonmissing.

• The CHECK constraint uses the WHERE expression to ensure that the only values of CapBusiness that are allowed are those greater than Cap1st or missing.

Initiating and Reading Audit Trails

proc datasets nolist;
audit capinfo;
initiate;
quit;

Initiating Generation Data Sets


genmax 옵션 (genmax=n)
If the data set already exists, you can use the GENMAX= option with the DATASETS procedure and the MODIFY statement
• n=0, no historical versions are kept (this is the default).
• n>0, the specified number of versions of the file that are are kept. The number includes
the base version.

Processing Generation Data Sets


profile
Biostatistics researcher Github: https://github.com/hoyajhl

0개의 댓글