BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
geetha1a2b3c
Calcite | Level 5

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?

1 ACCEPTED SOLUTION
5 REPLIES 5
PeterClemmensen
Tourmaline | Level 20

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;
geetha1a2b3c
Calcite | Level 5
Thanks draycut. I am looking for what went wrong. Why iam getting different result.I gonna use 'mon'||put(i,z2.) in later part of my code
Tom
Super User Tom
Super User

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));

 

geetha1a2b3c
Calcite | Level 5
I am trying use the above resolved like


%let perf=12;
%macro addall(dname,rrun);
%do j=1 %to &rrun;
%let z=%sysfunc(putn,(&j,z2.));
&dname._&&mon.&z;
%end;
%mend addall;


data new1;
set %addall(new,&perf.);
run;


Getting below error
data new1;
64
65 set %addall(new,&perf.);
ERROR: Expected open parenthesis after macro function name not found.
NOTE: Line generated by the macro variable "Z".
65 mon.(1,z2.))
_ _
22 22
200
ERROR 22-7: Invalid option name 1.

ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, ;, CUROBS, END, INDSNAME, KEY, KEYRESET, KEYS,
NOBS, OPEN, POINT, _DATA_, _LAST_, _NULL_.

ERROR 200-322: The symbol is not recognized and will be ignored.

NOTE: Line generated by the macro variable "Z".
65 new_&mon.
_
22
200
WARNING: Apparent symbolic reference MON not resolved.
ERROR: Expected open parenthesis after macro function name not found.
NOTE: Line generated by the macro variable "Z".
65 new_&mon.
____
180
WARNING: Apparent symbolic reference MON not resolved.
ERROR: Expected open parenthesis after macro function name not found.
NOTE: Line generated by the macro variable "Z".
65 new_&mon.
____
180
WARNING: Apparent symbolic reference MON not resolved.
ERROR: Expected open parenthesis after macro function name not found.
NOTE: Line generated by the macro variable "Z".
65 new_&mon.
____
180
WARNING: Apparent symbolic reference MON not resolved.
ERROR: Expected open parenthesis after macro function name not found.
NOTE: Line generated by the macro variable "Z".
65 new_&mon.
____
180
WARNING: Apparent symbolic reference MON not resolved.
ERROR: Expected open parenthesis after macro function name not found.
NOTE: Line generated by the macro variable "Z".
65 new_&mon.
____
180
WARNING: Apparent symbolic reference MON not resolved.
ERROR: Expected open parenthesis after macro function name not found.
NOTE: Line generated by the macro variable "Z".
65 new_&mon.
____
180
WARNING: Apparent symbolic reference MON not resolved.
ERROR: Expected open parenthesis after macro function name not found.
NOTE: Line generated by the macro variable "Z".
65 new_&mon.
____
180

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 5 replies
  • 1545 views
  • 1 like
  • 4 in conversation