主要参考UCB的教程了,都是些常用小技巧http://www.stat.berkeley.edu/classes/s100/sas.pdf
SAS Tips:
endsas; *终止交互语句
input x1 : comma. *17,244
_numeric_,_character_,_all_
proc contents
proc options
name =: 'R' /*匹配所有以R开头的观测*/
agegrp = 1 + (age>10) + (age>20) + (age>30) /*快速分组*/
attrib string length = $ 12 format = $char12.;
informat char $charw. /*保留变量前的空格*/
rate = ifn(state = 'beijing',7.5,2.5);
rate = ifc(state = 'beijing',2.5,7.5);
put 80*"-" ;
array x x1-x9;
do i = 1 to dim(x);
if x{i} = 9 then x{i} = .;
end;
array x x1-x9;
do over x;
if x = 9 then x = .;
end;
input id name $ x y z state$ salary
array list id -numeric-z /* id,x,y,z*/
keep x--state /* x y z state */
/* Character Strings */
cat - preserve all spaces
cats - remove trailing blanks
catt - remove all blanks
catx - join with separator
compress - remove char in a string
index - find position of string in source
repeat - repeat
reverse - reverse
scan - find the nth 'word'
substr -
/* Regular Expressions in SAS */
str = '275 main street'
wh = prxmatch('/\d /',str) * wh=3
str='Smith, John'
newstr = prxchange('s/(\w+?),(\w+?)/$2 $1/',-1,str);
/* The second argument is the number of changes to make; −1 means
to change all occurences.*/
/* Create Multiple Dataset */
data young old;
set all;
if age<15 then output young;
else output old;
run;
/* option */
nofmterr * eliminate errors produced by missing formats