BookmarkSubscribeRSS Feed
MellyJ13
Calcite | Level 5

Hi there

I am trying to split a dataset using a macro. I found this code online:

 

%macro split_data;
* Create the vertical macro variable list.;
proc sql noprint;
select distinct origin into :origin1-
from sashelp.cars;
%let numorigins = &sqlobs;
quit;
* Loop through each value and generate a data step ;
* to create the corresponding subset. ;
%do i = 1 %to &numorigins;
data cars_&&origin&i;
set sashelp.cars;
where origin = "&&origin&i";
run;
%end;
%mend split_data;
%split_data;

However, I get this error:

 

NOTE: Line generated by the invoked macro "SPLIT_DATA".
9       data cars_&&origin&i;  set sashelp.cars;  where origin = "&&origin&i";  run;
                  -
                  22
                  200

ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, (, /, ;,
              _DATA_, _LAST_, _NULL_.

ERROR 200-322: The symbol is not recognized and will be ignored.

I am not sure what is going wrong. Any help would be much appreciated.

2 REPLIES 2