BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jhabikaskumar26
Fluorite | Level 6
I want to create a macro variable suffix1 suffix2... Suffix12 variable such that
suffix1= 11 12 13
Suffix2= 21 22 23 so on
I tried using two do loop for it. But after each iteration new value get replaced with old one without storing it. Please do help me if anyone knows how I can code it in sas studio.
1 ACCEPTED SOLUTION
6 REPLIES 6
jhabikaskumar26
Fluorite | Level 6
I have attached below a pdf which contains snapshot of code and log. In that we can observe that suffix12 resolves to 123 in last iteration but I want it should contains 121 122 123.
Kurt_Bremser
Super User

Your pdf does not display in the preview.

Please post code by copy/pasting the text into a window opened with the "little running man" button, and logs and other fixed-format text into a window opened with the </> button.

jhabikaskumar26
Fluorite | Level 6
%macro data;
%do i=1 %to 12;
%do j=1 %to 3;
%let suffix&i.=&i&j;
%put &&suffix&i;
%end;%end;
%mend data;

%data;
SYMBOLGEN:  Macro variable I resolves to 12
SYMBOLGEN:  Macro variable J resolves to 1
MLOGIC(DATA):  %PUT &&suffix&i
SYMBOLGEN:  && resolves to &.
SYMBOLGEN:  Macro variable I resolves to 12
SYMBOLGEN:  Macro variable SUFFIX12 resolves to 121
121
MLOGIC(DATA):  %DO loop index variable J is now 2; loop will iterate again.
SYMBOLGEN:  Macro variable I resolves to 12
MLOGIC(DATA):  %LET (variable name is SUFFIX12)
SYMBOLGEN:  Macro variable I resolves to 12
SYMBOLGEN:  Macro variable J resolves to 2
MLOGIC(DATA):  %PUT &&suffix&i
SYMBOLGEN:  && resolves to &.
SYMBOLGEN:  Macro variable I resolves to 12
SYMBOLGEN:  Macro variable SUFFIX12 resolves to 122
122
MLOGIC(DATA):  %DO loop index variable J is now 3; loop will iterate again.
SYMBOLGEN:  Macro variable I resolves to 12
MLOGIC(DATA):  %LET (variable name is SUFFIX12)
SYMBOLGEN:  Macro variable I resolves to 12
SYMBOLGEN:  Macro variable J resolves to 3
MLOGIC(DATA):  %PUT &&suffix&i
SYMBOLGEN:  && resolves to &.
SYMBOLGEN:  Macro variable I resolves to 12
SYMBOLGEN:  Macro variable SUFFIX12 resolves to 123
123
MLOGIC(DATA):  %DO loop index variable J is now 4; loop will not iterate again.
MLOGIC(DATA):  %DO loop index variable I is now 13; loop will not iterate again.
MLOGIC(DATA):  Ending execution.
91
Here, I want macro variable suffix12= 121 122 123. Please do help me in modifying my existing code.
jhabikaskumar26
Fluorite | Level 6

Thank you for the help! It works.

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
  • 6 replies
  • 1663 views
  • 2 likes
  • 2 in conversation