Can someone help me with a macro that holds one week back date whenever ran?
data _null_;
call symput('yesterday', put(today()-8, mmddyy10.));
run;
&yesterday;
This is my code. Any better way using intnx or something else?
I'll go a step further than @PaigeMiller: why bother using a put statement to convert the number (date) into a character form regardless of how it is formatted? Also, you don't even need a datastep. e.g.:
%let yesterday=%eval(%sysfunc(today())-8); %put &yesterday;
@adityaa9z wrote:
Can someone help me with a macro that holds one week back date whenever ran?
data _null_;
call symput('yesterday', put(today()-8, mmddyy10.));
run;&yesterday;
This is my code. Any better way using intnx or something else?
Your code looks fine, intnx should give the same result so there's really no reason to prefer one over the other.
Your last line should say
%put &yesterday;
I would ask the question about why you want format mmddyy10. if you are going to use &yesterday in labels or titles, then that's a good format to use; if you are going to use this number in calculations, then you don't want a format. Also, it's not clear to me why you want -8 instead of -7, but that's entirely up to you.
I'll go a step further than @PaigeMiller: why bother using a put statement to convert the number (date) into a character form regardless of how it is formatted? Also, you don't even need a datastep. e.g.:
%let yesterday=%eval(%sysfunc(today())-8); %put &yesterday;
@art297 wrote:
why bother using a put statement to convert the number (date) into a character form regardless of how it is formatted?
For use in a TITLE statement?
For use in a LABEL statement?
Agreed .. IF that is how it is going to be used! However, NOT if it is only going to be used as a SAS date.
However, back to what I think @adityaa9z was asking, there is NO better way to calculate eight days before a date than doing what you did: a simple subtraction.
Art, CEO, AnalystFinder.com
@art297 wrote:
Agreed .. IF that is how it is going to be used! However, NOT if it is only going to be used as a SAS date.
So we're in agreement, and we're both saying the same thing!
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.