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 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 762 views
  • 0 likes
  • 2 in conversation