DATA Step, Macro, Functions and more

Macro for yesterday's date using sysfunc and datetime22.3 format

Accepted Solution Solved
Reply
Contributor
Posts: 30
Accepted Solution

Macro for yesterday's date using sysfunc and datetime22.3 format

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. 


Accepted Solutions
Solution
‎01-20-2016 11:12 AM
Respected Advisor
Posts: 3,799

Re: Macro for yesterday's date using sysfunc and datetime22.3 format

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

View solution in original post


All Replies
Respected Advisor
Posts: 3,799

Re: Macro for yesterday's date using sysfunc and datetime22.3 format

1975  %put NOTE: %sysfunc(intnx(DTDAY,%sysfunc(datetime()),-1,same),datetime22.3);
NOTE: 19JAN2016:06:36:11.653
Contributor
Posts: 30

Re: Macro for yesterday's date using sysfunc and datetime22.3 format

Posted in reply to data_null__

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. 

Solution
‎01-20-2016 11:12 AM
Respected Advisor
Posts: 3,799

Re: Macro for yesterday's date using sysfunc and datetime22.3 format

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

Contributor
Posts: 30

Re: Macro for yesterday's date using sysfunc and datetime22.3 format

Posted in reply to data_null__
Thanks.
Super User
Super User
Posts: 7,988

Re: Macro for yesterday's date using sysfunc and datetime22.3 format

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);
Contributor
Posts: 30

Re: Macro for yesterday's date using sysfunc and datetime22.3 format

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. 

Super User
Super User
Posts: 7,988

Re: Macro for yesterday's date using sysfunc and datetime22.3 format

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;

 

Super User
Posts: 7,854

Re: Macro for yesterday's date using sysfunc and datetime22.3 format

Another method:

data _null_;
call symput('yesterday',put((today()-1)*86400,datetime22.3));
run;
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 8 replies
  • 871 views
  • 1 like
  • 4 in conversation