SAS codes

TEMP·2021년 9월 20일
0

SAS

목록 보기
2/13
post-custom-banner

connect

libname name 'D:\chrome';

Import data

proc import 
out=work.name
datafile='original.xlsx'
dbms=xlsx
replace;
sheet='sheet1$';
getnames=Yes;
run;


proc import 
out=work.name
datafile='original.csv'
dbms=csv
replace;
getnames=Yes;
run;

proc import 
out=work.name
datafile='original.csv'
dbms=tab(쉼표나 한칸 띄어쓰기는 그냥 위에처럼)
replace;
getnames=Yes;
run;

Data setting

data new;
input name $ age @@;
cards;


;
run;

Data control

data new;
set old;
drop 변수명 (아니면 keep 변수명);
if var1=10 then var_new=var1*2;
if var2=9 then delete; (해당행 삭제)
if var3=8; (이 조건만 keep 나머지 delete);
if var4 in (10,11,12) then delete;
t+1; (t가 1부터 ... (_N_이랑 같음))
run;

Plot

proc sgplot data=pop;
series x=year y=pop/ markers markerattrs=(symbol=asterisk);
xaxis values=(1960 to 1995 by 5);
run;

corr & cov

proc corr data= z cov outp=Z_corr;
run;

data cov;
set Z_corr ;
if _TYPE_='COV';
keep z1-z3;
run;

data corr;
set Z_corr ;
if _TYPE_='CORR';
keep z1-z3;
run;

Matrix

proc iml;
use cov;
read all into A;
Det=det(A);
Trace=trace(A);
Inverse=inv(A);
print(Det);
print(Trace);
print(Inverse);

slice and create new matrix

data Q1;
input e1 - e6 p1 - p6;
cards;
121 22 74 223 54 254 132 17 77 232 50 249
108 30 80 175 40 300 123 32 79 192 64 315
122 49 87 266 41 223 129 31 96 250 55 319
77 37 66 178 80 209 131 23 67 291 48 310
140 35 71 175 38 261 110 24 96 239 42 268
108 37 57 241 59 245 47 22 87 231 40 217
124 39 52 194 72 242 125 32 87 227 30 324
130 34 89 200 85 242 129 29 102 234 58 300
149 55 91 198 50 277 130 26 104 256 58 270
129 38 72 162 47 268 147 47 82 240 30 322
154 37 87 170 60 244 159 37 80 227 58 317
145 33 88 208 51 228 135 41 83 216 39 306
112 40 60 232 29 279 100 35 83 183 57 242
120 39 73 159 39 233 149 37 94 227 30 240
118 21 83 152 88 233 149 38 78 258 42 271
141 42 80 195 36 241 153 27 89 283 66 291
135 49 73 152 42 249 136 31 83 257 31 311
151 37 76 223 74 268 97 36 100 252 30 225
97 46 83 164 31 243 141 37 105 250 27 243
109 42 82 188 57 267 164 32 76 187 30 264
;
proc print;
run;
proc corr data = Q1 cov outp = Q1_corr;
var e1 -- e6;
run;
proc iml ;
use Q1_corr;
read all into A;
cov = A[1:6, 1:6];
corr = A[10:15 , 1:6];
print cov corr;
cov_val = eigval(cov);
cov_vec = eigvec(cov);
corr_val = eigval(corr);
corr_vec = eigvec(corr);
print cov_val;
print cov_vec;
print corr_val;
print corr_vec;
create cov_values;
append var {cov_val};
close cov_values;
create corr_values;
append var {corr_val};
close corr_values;
run; 
quit;
post-custom-banner

0개의 댓글