BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
david27
Quartz | Level 8

 

This is what I have-- have.sas7bdat

 

I want to create a list of macro variables in a way that when I invoke

want_1_3 i get MDX

want_2_2 i get A4 3.0 4dr

 

How should I proceed?

 

proc sort data=sashelp.cars nodupkey out=cars(keep=make model);
	by make model;
run;

data have;
	set cars;
	by make model;
	retain id_groups 0;
	if first.make then
		do;
			id_groups+1;
			id_value_groups=1;
		end;
	else
		do;
			id_value_groups+1;
		end;
run;

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

This?

data have;
	set cars;
	by make model;
	retain id_groups 0;
	if first.make then
		do;
			id_groups+1;
			id_value_groups=1;
		end;
	else
		do;
			id_value_groups+1;
		end;

   call symputx(catx('_','Make',id_groups,Id_value_groups),Model);
run;

%put &make_1_3;
%put &make_2_2;

If the only purpose of the data step is to create the macro variables then use a DATA _NULL_ as you don't need the data set.

 

Where does SQL come into this? SQL doesn't use BY  groups per se.

View solution in original post

2 REPLIES 2
ballardw
Super User

This?

data have;
	set cars;
	by make model;
	retain id_groups 0;
	if first.make then
		do;
			id_groups+1;
			id_value_groups=1;
		end;
	else
		do;
			id_value_groups+1;
		end;

   call symputx(catx('_','Make',id_groups,Id_value_groups),Model);
run;

%put &make_1_3;
%put &make_2_2;

If the only purpose of the data step is to create the macro variables then use a DATA _NULL_ as you don't need the data set.

 

Where does SQL come into this? SQL doesn't use BY  groups per se.

david27
Quartz | Level 8

True. I dont know why I was thinking this can be done only by SQL. Thank You very much @ballardw 

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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