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

How to generate a new macro variable for each row?

 

Data ConsentInfo&j.;
length record $4000;
set info_1;
i=_n_;
record=cats("'", '{ "firstName" : ',' "',firstName,'", ',' "lastName" : ','"',lastName,'", ','"email" :',
'"',email,'"}',"'");
call symputx('NewRecord',record,'g');	
run;
1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Are you asking how to USE the macro variables once you have them?

 

You can type their full name:

%put &NewRecord1 ;
%put &NewRecord2 ;

You can use another macro variable to help you build up the name you want to reference.  You will need to double up the first &.  The && will be converted to & and signal to the macro processor to scan the text again to resolve the resulting macro variable reference.

%let i=1;
%put &&NewRecord&i ;

View solution in original post

3 REPLIES 3
Tom
Super User Tom
Super User

You have to use a different macro variable NAME to prevent writing the same macro variable over and over.

call symputx(cats('NewRecord',i),record,'g');	
alepage
Barite | Level 11

Is it possible to add a %put NewRecord || i;  

If after that I do a call execute how can I passed each macro variable

Tom
Super User Tom
Super User

Are you asking how to USE the macro variables once you have them?

 

You can type their full name:

%put &NewRecord1 ;
%put &NewRecord2 ;

You can use another macro variable to help you build up the name you want to reference.  You will need to double up the first &.  The && will be converted to & and signal to the macro processor to scan the text again to resolve the resulting macro variable reference.

%let i=1;
%put &&NewRecord&i ;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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
  • 3 replies
  • 1306 views
  • 1 like
  • 2 in conversation