See this:
%macro data;
%do i=1 %to 12;
%let suffix&i=;
%do j=1 %to 3;
%let suffix&i. = &&suffix&i. &i&j;
%end;
%put &&suffix&i;
%end;
%mend data;
%data
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.
%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.
See this:
%macro data;
%do i=1 %to 12;
%let suffix&i=;
%do j=1 %to 3;
%let suffix&i. = &&suffix&i. &i&j;
%end;
%put &&suffix&i;
%end;
%mend data;
%data
Thank you for the help! It works.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.