08-31-2011 03:27 PM
I have a field called CLIENT_NAME that has several different entries that can change depending on the dataset I'm feeding in. Because there is room for variation, using a macro to define the CLIENT_NAME values I want to use won't work each time. Is there a way to use a DO statement to create a loop that will go through every single unique value for a given variable? For instance, if I have 26 Client Names in a given dataset, the DO statement would run through the associated block of code 26 times, ultimately producing 26 datasets.
08-31-2011 03:42 PM
Normally to generate multiple datasets you will need to use some type of code generation tool. Either SAS macro code or you can do it yourself with a data step and a %INC.
filename code temp;
set have ;
by client_name ;
where = quote(trim(client_name));
put 'data split_' client_name ';'
/ ' set have;'
/ ' where client_name=' where ';'
%inc code / source2 ;
08-31-2011 03:57 PM
If the goal is to create separate datasets, and then deal with each separately, why not use a hash? e.g.:
data _null_ ;
dcl hash hh ( ) ;
hh.definekey ('k' ) ;
hh.definedata ('sex', 'name', 'age', 'height', 'weight') ;
hh.definedone () ;
do until(mod(k,5)=0 or last);
set sashelp.class end=last ;