What went wrong?
I wrote below part to get the third month from date macro.
%let date=2017-01-01;
%let a_SASdate=%sysfunc(inputn(&date.,yymmdd10.)) ;
%let b=%sysfunc(putn(&a_SASdate.,yymmn6.)) ;
%let et=%sysfunc(intnx(month,%sysfunc(inputn(&date.,yymmdd10.)),2,s),yymmn6.);
%put &a_SASdate. &b. &et.;
I wrote below code to create macro variable for each date.
data new;
do i=1 to 12;
call symput('mon'||put(i,z2.),put(intnx('month',&et.,i),yymmn6.));
a=symget('mon'||put(i,z2.));
output;
end;
run;
Expected output
i a
1 201704
2 201705
3 201706
4 201707
5 201708
6 201709
7 201710
8 201711
9 201712
10 201801
11 201801
12 201803
But what iam getting is
1 251204
2 251205
3 251206
4 251207
5 251208
6 251209
7 251210
8 251211
9 251212
10 251301
11 251302
12 251303
What went wrong?
There's a comma right after putn that does not belong there.
Not sure where your error is since I have not checked.
However, you are overcomplicating things massively in my opinion. You can do like this to get your desired result
data dates(keep= i a);
date='01jan2017'd;
monthsahead=3;
do i=1 to 12;
a=intnx('month', date, i+months-1, 'sameday');
output;
end;
format a yymmn6.;
run;
The data step is fine.
%let et="&sysdate9"d ;
data new;
length i 8 a $6 ;
do i=1 to 12;
call symputX('mon'||put(i,z2.),put(intnx('month',&et.,i),yymmn6.));
a=symget('mon'||put(i,z2.));
output;
put i= a= ;
end;
run;
But it is assuming that ET contains a date value, and it does not.
Why not just store the date value into ET?
%let et=%sysfunc(intnx(month,%sysfunc(inputn(&date.,yymmdd10.)),2,s));
There's a comma right after putn that does not belong there.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.