I want to create a global macro for yesterdays date using sysfunc (without using today() ). And I want the output in datetime22.3 format. Couldn't figured out by myself.
2027 %put NOTE: %sysfunc(intnx(DTDAY,%sysfunc(datetime()),-1,begin),datetime22.3);
NOTE: 19JAN2016:00:00:00.000
You might want to read about INTNX
1975 %put NOTE: %sysfunc(intnx(DTDAY,%sysfunc(datetime()),-1,same),datetime22.3);
NOTE: 19JAN2016:06:36:11.653
Thanks. I just tried and I got the following output: 19JAN2016:11:03:57.512. Is there anyway I can get 19JAN2016:00:00:00.000 as an output. I want to oull up all the transaction from the begining of the day yesterday.
Thanks once again.
2027 %put NOTE: %sysfunc(intnx(DTDAY,%sysfunc(datetime()),-1,begin),datetime22.3);
NOTE: 19JAN2016:00:00:00.000
You might want to read about INTNX
Sorry, couple of questions:
Why do you need to keep a macro variable with today()-1, what is wrong with just using that?
Why can you not use today() function which does this processing, why try to re-implement it?
To put it in the log do:
%put %sysfunc(today(),datetime22.0);
I got the following output when I used your code.
01JAN1960:05:41:13
I hoep thats answers the question why I prefer using sysfunc.
Not really, you didn't mention that in the original request. You can merely modify the code slightly:
%put %sysfunc(today(),date9.):00:00:00.000;
Another method:
data _null_;
call symput('yesterday',put((today()-1)*86400,datetime22.3));
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.