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!
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.