BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
hellohere
Pyrite | Level 9
I need stack a series into a dataset/column. Tried and failed. How to do it? %let var1=205; %let var3=306; %let var3=409; data mvtemp; input var note $8.; datalines; &var1. X &var2. Xx &var3. YYY ; run;quit;
1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

But a workaround way is using RESOLVE() or SYMGETN().

 

%let var1=205; 
%let var2=306; 
%let var3=409; 

data mvtemp;
input var $ note $; 
new_var1=input(resolve(var),best.);
new_var2=symgetn(compress(var,'&.'));
datalines; 
&var1. X 
&var2. Xx 
&var3. YYY 
; 
run;

View solution in original post

5 REPLIES 5
hellohere
Pyrite | Level 9
Here is a post, which is close. https://communities.sas.com/t5/SAS-Programming/Passing-a-Macro-Variable-value-into-a-data-step/m-p/7... BUT I need use datalines to stack, rather than use = to assign.
Ksharp
Super User

Unfortunately, DATALINES or CARDS does not support macro variable ,you need put these macro variable into a text file ,and read this text file .

This feature has already been mentioned in sas documentation.

Ksharp
Super User

But a workaround way is using RESOLVE() or SYMGETN().

 

%let var1=205; 
%let var2=306; 
%let var3=409; 

data mvtemp;
input var $ note $; 
new_var1=input(resolve(var),best.);
new_var2=symgetn(compress(var,'&.'));
datalines; 
&var1. X 
&var2. Xx 
&var3. YYY 
; 
run;
hellohere
Pyrite | Level 9

Thanks, It works. 

 

I take from prev.  post. The code below is ok also. 

 

%let mvars=&_ref_1.@&_ref_2.@&_ref_3.@&_ref_4.@&_ref_5.@&_ref_6.@&_ref_7.@&_ref_8.@&_ref_9.;
 %let mvars2=max@min@max@min@max@min@max@min@max;
	data &indexout._&dt._mm_ind;
	do i= 1 to countw(symget('mvars'),'@');
		length mm_indx note $8. ;
			mm_indx=scan(symget('mvars'),i,'@');
			note=scan(symget('mvars2'),i,'@');
		output;
	end;
	run;quit;
Tom
Super User Tom
Super User

I am not sure what you mean by "stack".  But it looks like you want to resolve a series of macro variables with the same base name and a numeric suffix.  Why not use SYMGET() function?

data mvtemp;
  length var $32 ;
  var = symget(cats('var',_n_));
  input note $8.;
cards;
X
Xx
YYY
;

Or since it looks like the values of the VARxx macro variables have digit strings perhaps you want to use SYMGETN() instead?

data mvtemp;
  value = symgetn(cats('var',_n_));
  input note $8.;
cards;
X
Xx
YYY
;

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 Update

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
  • 5 replies
  • 375 views
  • 0 likes
  • 3 in conversation