BookmarkSubscribeRSS Feed
SKHD
Calcite | Level 5

Hi, I want to generate time stamp with end of last month and pass on to SAS macro. I use code below to generate datetime with end of last month.

 

%LET QUOTE = %BQUOTE(');

%LET EVAL_DT = &QUOTE%SYSFUNC(PUTN(%SYSFUNC(INTNX(MONTH,%SYSFUNC(TODAY()),-1.,E)),YYMMDD10.))&QUOTE;

 

I was hoping if there was anything similar to generate time stamp that could give me timestamp with end of last month like '2018-05-31:23:59:59.9999' ?

2 REPLIES 2
ballardw
Super User

@SKHD wrote:

Hi, I want to generate time stamp with end of last month and pass on to SAS macro. I use code below to generate datetime with end of last month.

 

%LET QUOTE = %BQUOTE(');

%LET EVAL_DT = &QUOTE%SYSFUNC(PUTN(%SYSFUNC(INTNX(MONTH,%SYSFUNC(TODAY()),-1.,E)),YYMMDD10.))&QUOTE;

 

I was hoping if there was anything similar to generate time stamp that could give me timestamp with end of last month like '2018-05-31:23:59:59.9999' ?


If people are going to see or use the value then it may be worth making some string like that.

Are you sending this to an external database system? If not you would probably be much better off if the value was an actual SAS datetime value.

You might show how you intend to use the code/ macro value. It may very well be that there is no reason to create a macro string value at all.

 

PaigeMiller
Diamond | Level 26

Well, it seems you are working very hard to do something very simple.

 

If you want the end of the last month, why not use the start time of the current month and then test for any time LESS THAN the start time of the current month?

 

But, if you really really really need YYYY-MM-DD:23:59:59.9999, first you don't need the quotes, and it's hard to imagine a reason why you want it formatted to human readable form, when all you need is the true datetime value;

 

data _null_;
    y='01JUL17:00:00:00'dt - 0.0001;
    call symputx('eval_dt',put(y,20.4));
run;
--
Paige Miller

sas-innovate-2024.png

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.

 

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
  • 2 replies
  • 725 views
  • 0 likes
  • 3 in conversation