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: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 399 views
  • 0 likes
  • 3 in conversation