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

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 384 views
  • 0 likes
  • 3 in conversation