BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
SAS_Question
Quartz | Level 8
/*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! 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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;

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

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_Question
Quartz | Level 8
SWEET! I love your simple solutions @Tom! Great! Thanks al lot! 🙂

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 249 views
  • 0 likes
  • 2 in conversation