I am trying to create two macro dates using enterprise guide 7.1 SAS version 9.4. The first date is based off of today's date and works fine. alpha is yesterday. The second date is suppose to be the same day in the prior month from alpha. So if today is June 13, alpha is jun 12 and beta would be may 12.
data _null_;
call symputx('alpha', PUT(intnx('DAY',%SYSFUNC(today()),-1), date9.)); * yesterday;
call symputx('beta', PUT(intnx('MONTH',%SYSFUNC(&alpha,-1), date9.)); * last month same day;
RUN;
Corrected
data _null_;
call symputx('alpha', PUT(intnx('DAY',today(),-1), date9.)); * yesterday;
call symputx('beta', PUT(intnx('MONTH',today()-1,-1,'s'), date9.)); * last month same day;
RUN;
%put α
%put β
data _null_;
call symputx('alpha', PUT(intnx('DAY',today(),-1), date9.)); * yesterday;
call symputx('beta', PUT(intnx('MONTH',today(),-1,'s'), date9.)); * last month same day;
RUN;
%put α
%put β
Corrected
data _null_;
call symputx('alpha', PUT(intnx('DAY',today(),-1), date9.)); * yesterday;
call symputx('beta', PUT(intnx('MONTH',today()-1,-1,'s'), date9.)); * last month same day;
RUN;
%put α
%put β
NOTE: Writing TAGSETS.SASREPORT13(EGSR) Body file: EGSR
24
25 GOPTIONS ACCESSIBLE;
26 data _null_;
27 call symputx('alpha', PUT(intnx('DAY',today(),-1), date9.)); * yesterday;
28 call symputx('beta', PUT(intnx('MONTH',today(),-1,-1,'s'), date9.)); * yesterday;
29 RUN;
NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column).
28:51
NOTE: Argument 5 to function INTNX('MONTH',21348,-1,' -1','s') at line 28 column 26 is invalid.
_ERROR_=1 _N_=1
NOTE: Mathematical operations could not be performed at the following places. The results of the operations have been set to
missing values.
Each place is given by: (Number of times) at (Line):(Column).
1 at 28:26
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.00 seconds
@pangea17 you didn't quite exactly copy paste my code
there is a difference in the 2nd call symputx with yours and mine. Kindly review thoroughly. Please and thank you
mine: call symputx('beta', PUT(intnx('MONTH',today()-1,-1,'s'), date9.)); * last month same day;
yours: call symputx('beta', PUT(intnx('MONTH',today(),-1,-1,'s'), date9.)); * yesterday;
That did work great! Thank you.
I'm glad. Have fun!
@pangea17 wrote:
I am trying to create two macro dates using enterprise guide 7.1 SAS version 9.4. The first date is based off of today's date and works fine. alpha is yesterday. The second date is suppose to be the same day in the prior month from alpha. So if today is June 13, alpha is jun 12 and beta would be may 12.
data _null_;
call symputx('alpha', PUT(intnx('DAY',%SYSFUNC(today()),-1), date9.)); * yesterday;
call symputx('beta', PUT(intnx('MONTH',%SYSFUNC(&alpha,-1), date9.)); * last month same day;
RUN;
In your code, the macro preprocessor tries to resolve &alpha before it is created.
%sysfunc only accepts a data step function call as its argument, and not a macro variable.
A previous day is calculated best by simply subtracting 1 from a date.
data _null_;
call symputx('alpha', put(today()-1, date9.)); * yesterday;
call symputx('beta', put(intnx('month',today()-1,-1), date9.)); * last month same day;
run;
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.
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.