BookmarkSubscribeRSS Feed
SASPhile
Quartz | Level 8
If there is a variable date which takes value 1103 where 11 is year and 03 is month.
how to create macro variables
Mth1 which takes value Mar-2011
Mth2 which takes value Feb-2011
4 REPLIES 4
SPR
Quartz | Level 8 SPR
Quartz | Level 8
Hello SASPhile,

This code does the trick:
[pre]
data _null_;
vd=1103;
m=MOD(vd,100);
y=2000+INT(vd/100);
d=PUT(MDY(m,01,y),MONYY7.);
Mth1=SUBSTR(d,1,3)||"-"||SUBSTR(d,4);
call SYMPUTX('Mth1',Mth1);
run;
%put Mth1=&Mth1;
[/pre]
Sincerely,
SPR
SASPhile
Quartz | Level 8
Thank you.
I have a question.
In call symputx routine, &i is not allowed.This throws an error.
How to pass the variable MTH&i to a macro variable &MTH&i.



%do i= 2 %to 6;
d&i.=put(intnx('month',input(d,date9.),%eval(1-&i.)),MONYY7.);
Mth&i.=SUBSTR(d&i.,1,3)||"-"||SUBSTR(d&i.,4);
call SYMPUTX('MTH&i.',Mth&i.);
%end;
SASJedi
Ammonite | Level 13
Change the single quotes in:
call SYMPUTX('MTH&i.',Mth&i.);

to double quotes:
call SYMPUTX("MTH&i.",Mth&i.);

and it should work for you...
Check out my Jedi SAS Tricks for SAS Users
Ksharp
Super User
[pre]
data a;
input a $;
a=cats(a,'01');
want_a=input(a,yymmdd8.);
format want_a monyy7.;

put a= want_a=;
datalines;
1102
1104
;
run;
[/pre]

Ksharp

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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
  • 4 replies
  • 1654 views
  • 0 likes
  • 4 in conversation