Char to Date conversion in SAS

July 14th, 2008
1
2
3
4
5
DATA lab.rat;
	SET lab.rat;
	myday = INPUT(Financials_Date, YYMMDD10.);
	FORMAT myday YYMMDD10.;
RUN;

Updating Data Sets

July 2nd, 2008
1
2
3
DATA orig;
        update orig upd;
        by id;

WHERE statements in SAS

July 2nd, 2008
1
2
3
4
5
where salary between 2000 and 50000;
where city contains 'bay';
where x is missing and y is not missing;
where name like 'S%'; *% for any # of chars _ for one
where name *= 'smith'; * select based on soundex algor.

Concatenating Data Sets in SAS

July 2nd, 2008
1
2
3
/**** append new to master.enroll ****/
PROC APPEND base=master.enroll new=new;
run;

Do loops in SAS

July 2nd, 2008
1
2
3
4
5
6
7
do; ~ groups blocks of statement array elements
do over arrayname; ~ process array elements
do var=start to end <by inc>; ~ - range of numeric values 
do var=list-of-values;
do while(expression); (expression evaluated before loop)
do until(express); (expression evaluated after loop)
</by>

Array in SAS

July 1st, 2008
1
2
3
4
5
6
7
8
/**** Declarations ****/
array arrayname variable_list < $> < (startingvalues)>;
array arrayname{n} varaible_list < $> < (startingvalues)>;
 
array x x1-x9;
do i = 1 to dim(x);
   if x{i} = 9 then x{i}=.;
   end;

Restrictions:

1
2
3
4
5
All variables must be of the same type.
An array can not have the same name as a variable
You can use the keyword _temporary_ instead of a variable list.
The statement array x{3}; generates variables x1, x2, and x3.
The function dim returns the number of elements in an array.

Loop in SAS

June 27th, 2008
1
2
3
4
if x < 5 then do:
        group = "A";
        use = 0;
        end;

Shortcuts in grouping variables

June 27th, 2008
1
2
3
4
5
6
7
/**** Example ****/
agegrp = 1;
if 20 < age <= 30 then agegrp = 2;
if 30 < age <= 40 then agegrp =3;
if age > 40 then agegrp =4;
/**** is equivalent to ****/
agegrp = 1 + (age > 20) + (age > 30) + (age > 40);

stop, abort, return

June 25th, 2008
1
2
3
4
stop ~ immediately discountinue entire execution of the dat step
abort ~ like stop, but set _error_ to 1
error ~ like abort, but prints a message to the SAS log
return ~ begin execution of next iteration of data step

Invoking SAS in linux

June 24th, 2008
1
2
sas -work .
sas -work /some/other/directory