BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
adityaa9z
Obsidian | Level 7

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?

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

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

5 REPLIES 5
PaigeMiller
Diamond | Level 26

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

--
Paige Miller
art297
Opal | Level 21

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;
PaigeMiller
Diamond | Level 26

@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?

--
Paige Miller
art297
Opal | Level 21

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

 

PaigeMiller
Diamond | Level 26

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

--
Paige Miller

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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