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 201803But 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 251303What 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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
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!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.