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
SAS Super FREQ
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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

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