DATA Step, Macro, Functions and more

Macro to hold 1 week back date

Accepted Solution Solved
Reply
Contributor
Posts: 27
Accepted Solution

Macro to hold 1 week back date

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?


Accepted Solutions
Solution
‎05-22-2017 03:12 PM
PROC Star
Posts: 7,492

Re: Macro to hold 1 week back date

Posted in reply to adityaa9z

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;

View solution in original post


All Replies
Trusted Advisor
Posts: 1,934

Re: Macro to hold 1 week back date

[ Edited ]
Posted in reply to adityaa9z

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. 

Solution
‎05-22-2017 03:12 PM
PROC Star
Posts: 7,492

Re: Macro to hold 1 week back date

Posted in reply to adityaa9z

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;
Trusted Advisor
Posts: 1,934

Re: Macro to hold 1 week back date


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?

PROC Star
Posts: 7,492

Re: Macro to hold 1 week back date

Posted in reply to PaigeMiller

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

 

Trusted Advisor
Posts: 1,934

Re: Macro to hold 1 week back date


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!

☑ This topic is solved.

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

Discussion stats
  • 5 replies
  • 185 views
  • 1 like
  • 3 in conversation