libname ex 'h:\temp';
proc format library=ex;
value sev 1='mile'
2='moderate'
3='severe';
run;
/* To use the permanent format */
libname ff 'h:\temp';
options fmtsearch=(ff);
SAS tips which I keep forgetting :)
libname ex 'h:\temp';
proc format library=ex;
value sev 1='mile'
2='moderate'
3='severe';
run;
data exemplary;
do variety=1 to 2;
do exposure=1 to 3;
input height @@; output;
end;
end;
datalines; /* expected population means */
14 16 21
10 15 16
run;
proc glmpower data=exemplary;
class variety exposure;
model height=variety|exposure;
contrast "variety" variety 1 -1;
contrast "exp 1 vs 3" exposure 1 0 -1;
contrast "inter" variety*exposure 1 1 1, -1 -1 -1;
power stddev=5
ntotal=60
power=.;
plot x=n min=30 max=90;
run;
# combine strings
data comb_txt;
input id $4. +1 categry $7.;
aa = compress(categry," ,");
n=length(aa);
cat=substr(aa,1,1);
do i=2 to n;
cat=trim(left(cat))||", "||substr(aa,i,1);
end;
cards;
0149 2, 5
0148 7,
0150 8, 5
0151 3, 4, 6
0152
PROC IMPORT datafile='pathname' out=mylib.data dbms=dlm replace; delimiter='!'; getnames=yes; /* csv file */ PROC IMPORT datafile='pathname' out=mylib.data dbms=csv replace; getnames=yes;/* proc export (csv) */ proc export data=sasuser.houses outfile="/myfiles/class.csv" dbms=csv; /* input */ input (x1-x35)($1.); input name $10. +3 x1 7. x2 6. x3 6.; input (name x1-x3)($10. +3 7. 2*6.); input (name x1-x3)($10. +3 7. 2*6.) (y1-y5)(2*6. 3. 2*8.); /* character -> numeric */ input(num, 8.0); /* numeric -> character */ left(char); put(char, 1.) /* input 2*3 table */
do i='No','Yes';
do i=1,2,3,4;
data twobythree; do i = 1 to 2; do j =1 to 3; input x @@; output; end; end; cards; 11 12 13 21 22 23 run; /* datastep for 1 obs for a line */ data methods; input irrig $ @@; do bloc=1 to 8; input fruitwt @@; logfwt=log(fruitwt); output; end; datalines; trickle 450 469 249 125 280 352 221 251 basin 358 512 281 58 352 293 283 186 spray 331 402 183 70 258 281 219 46 sprnkler 317 423 379 63 289 239 269 357 flood 245 380 263 62 336 282 171 98 run; /* generate 2 datasets */ data males females; set class; if sex='M' then output males; else output females; run; /* Missing */ data class; set aa; array x _numeric_; do over x; if x=999 then x=.; /* missing */ end; run; /* random number */ data random(drop=n); do n=1 to 10; x=uniform(0); /* 0 means the seed number depends on current time */ output; end; run;/* random number generator */ rannor(seed); ranuni(seed); uniform(seed); ranbin(seed,n,p); rancau(seed); ranexp(seed); rangam(seed, alpha); ranpoi(seed, lambda); rantbl(seed, p1, p2...,pn);