## macro Variable List

Super Contributor
Posts: 713

# macro Variable List

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
Super Contributor
Posts: 366

## Re: macro Variable List

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
Super Contributor
Posts: 713

## Re: macro Variable List

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;
SAS Employee
Posts: 117

## Re: macro Variable List

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...
Super User
Posts: 10,770

## Re: macro Variable List

[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
Discussion stats
• 4 replies
• 192 views
• 0 likes
• 4 in conversation