DATA Step, Macro, Functions and more

How do I generate timestamp YYYY-MM-DD:23:59:59.9999?

Reply
Frequent Learner
Posts: 1

How do I generate timestamp YYYY-MM-DD:23:59:59.9999?

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

Super User
Posts: 13,517

Re: How do I generate timestamp YYYY-MM-DD:23:59:59.9999?


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

 

Respected Advisor
Posts: 2,997

Re: How do I generate timestamp YYYY-MM-DD:23:59:59.9999?

[ Edited ]

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
Ask a Question
Discussion stats
  • 2 replies
  • 53 views
  • 0 likes
  • 3 in conversation