BookmarkSubscribeRSS Feed
thanikondharish
Calcite | Level 5
%let I=1;
%let state1=ap;
%let ap1=India;
%let India1=Asia;
/*First*/
I want to resolve ap1 macro variable I wrote like below.
Data ex1;
Name="&&&state&I." ;
Run;

/*Second*/
I want to resolve India1 macro variable I wrote like below.
Data ex2;
Name="&&&&&&&state&I.";
Run;
But above 2 codes not working the macro variables are not resolving
5 REPLIES 5
PeterClemmensen
Tourmaline | Level 20

Just to be clear, what do you want the value of Name to be in the two code snippets?

thanikondharish
Calcite | Level 5
First: name=India
Second name=asia
PeterClemmensen
Tourmaline | Level 20

Are the macro variables fixed or can I change them a bit? Seems easier not having the 1 in all of them

Jagadishkatam
Amethyst | Level 16

Please try the below code

 


Data ex1;
Name="&&&state&I.&&i" ;
Run;
Thanks,
Jag
Shmuel
Garnet | Level 18

Change your code into:

%let I=1;
%let state1=ap;
%let ap1=India;
%let India1=Asia;
/*First  - I want to resolve ap1 macro variable I wrote like below. */
Data ex1;
Name="&&&state&I&&I." ; 
Run;

/*Second*/
I want to resolve India1 macro variable I wrote like below.
Data ex2;
Name="&&&&&&state&I&&i.";
Run;

Remember - sas resolves macros step by step. Each pair of && become a single &, thus:

1) &&&&&&state&I&&i

2) &&&state1&i

3) &&ap1

4) India

 

 

 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 5 replies
  • 730 views
  • 2 likes
  • 4 in conversation