/*Have*/
data insimp2;
set sashelp.cars(keep=make type origin cylinders horsepower);
run;
proc sql;
select distinct make into: vak1-
from work.insimp2;
quit;
%put &sqlobs.;
%put &vak1.;
%MACRO GDATA(nbs,vak);
proc sql;
create table work.insimp2_&nbs. as
select * from work.insimp2
group by cylinders
having (Make="&vak.")
order by origin, horsepower asc;
quit;
%MEND GDATA;
/* WANT */
/*
I Want for every make of the car to run the macro. So the macro dynamically creates datasets with 1 make of every car
Obviously I can do it like this:
%GDATA(1,&vak1.);
%GDATA(2,&vak2.);
etc.
%GDATA(38,&vak38.);
But in this case the dataset must always have 38 obs to keep working.
But I want this macro to run without knowing that there are 38 makes (like in this case).
So maybe there could be 20 or maybe 200 makes..
the macro should run without hardcoding the obs.
How do I do this?
*/
Thanks in Advance guys!
No need to move the data into macro variables to generate the macro calls.
Just use the data in a data step instead.
proc freq data=insimp2;
tables make / noprint out=counts;
run;
data _null_;
set counts;
call execute(cats('%nrstr(%gdata)(',_n_,make,')'));
run;
No need to move the data into macro variables to generate the macro calls.
Just use the data in a data step instead.
proc freq data=insimp2;
tables make / noprint out=counts;
run;
data _null_;
set counts;
call execute(cats('%nrstr(%gdata)(',_n_,make,')'));
run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.