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

Hello,

 

I want to build a macro which shows me current date in datetime format and a date -1 month.

 

%let date1 = %sysfunc(datetime(),DATETIME16.);

%let date_prev=%sysfunc(intnx(month,"%sysfunc(putn("&date1"d,DATETIME16.))"d,-1,s),DATETIME16.);

%put &date_prev.;

 

Date1 gives me good results but in date_prev i have 31DEC59:23:53:55.

 

How I should change this macro to have date_prev = 07AUG2017time ?

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

Why not do it in a data step like this?

 

data _null_;
	date1 = datetime();
	date_prev = intnx('dtmonth', date1, -1, 's');
	format date1 date_prev datetime16.;
	put date1= date_prev=;
run;

View solution in original post

2 REPLIES 2
PeterClemmensen
Tourmaline | Level 20

Why not do it in a data step like this?

 

data _null_;
	date1 = datetime();
	date_prev = intnx('dtmonth', date1, -1, 's');
	format date1 date_prev datetime16.;
	put date1= date_prev=;
run;
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Its been asked many times here.  The question is why would you need to?  You can always get yesterdays date by doing intnx('year',today,-1); so why bother going through all the effort of calculating it, then storing it as text - macro is always text - then trying to use that text in your code.  Its madness.  

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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
  • 2 replies
  • 860 views
  • 1 like
  • 3 in conversation