BookmarkSubscribeRSS Feed

Create the dttime format to mirror the various dtdate formats.




data _null_;


   put dt dtdate.;  * yields current date ;

   put dt dttime.;  * yields current time ;



It seems obvious to me, but perhaps I'm missing a good reason why this format does not exist?

Lapis Lazuli | Level 10

You can use the datepart and timepart functions to return date and time, respectively, from a datetime variable.

Rhodochrosite | Level 12

Thanks Paul, I'm aware of that.  


I'm calling these formats in macro code.


So, currently, I have to do something like (contrived example):


%let MyMvar = %sysfunc(datetime(),dtdate.) %sysfunc(timepart(%sysfunc(datetime()),time.);


Instead, I wish I could do:


%let MyMvar = %sysfunc(datetime(),dtdate.) %sysfunc(datetime(),dttime.);


(Yes, I know I could use date() and time() respectively - it's a contrived example.)


So, as with most things in SAS, There Is More Than One Way To Do It (any Perl programmers here?).  And there is a workaround as you have suggested.


I still think the dttime format would be useful, seems to naturally follow from the dt* date formats, and would plug a minor hole in the extensive suite of SAS formats.


I'll be the first to admit this is a low priority suggestion.  At the same time, and while not knowing the internals of format code, with the existing timepart code and time format code, I suspect a dttime format would be easy for SAS R&D to create.  (But of course this is just conjecture on my part.)

SAS Employee
SAS Employee

The TIMEAMPMw.d format writes time and datetime values as hours, minutes, and seconds in the form with AM or PM.

Rhodochrosite | Level 12

Thanks @kmw, unfortunately that does not meet my needs.  Unless I can get 24 hour time and suppress the AM/PM?


See example above ("Instead, I wish I could do").