BookmarkSubscribeRSS Feed
niejung
Obsidian | Level 7

I couldn't find a good sample to convert the date that I want.   NEED HELP! 

This is the format I want "mm/dd/yyyy hh:mm:ss" 

options tz='America/New_York';  
data NY;
   NY_DT=datetime();  
   format NY_DT  datetime19.; 
	put NY_DT=datetime19.;
run;


42 options tz='America/New_York';
43 data NY;
44 NY_DT=datetime();
2 The SAS System 08:31 Tuesday, July 21, 2020

45 format NY_DT datetime19.;
46 put NY_DT=datetime19.;
47 run;

NY_DT=26JUL2020:13:10:11
NOTE: The data set WORK.NY has 1 observations and 1 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.01 seconds

3 REPLIES 3
niejung
Obsidian | Level 7

Okay.  I should be more patient before I do more posts.   I got it too work by referring this post (https://communities.sas.com/t5/SAS-Programming/datetime-informat-mm-dd-yyyy-hh-mm-ss-24-hour-time-fo..."  

 

If anyone who has better or simple way to do the format, please share.  😊

 

proc format library=work;
picture dtmmddyy (default=19)
low-high = '%0m/%0d/%Y %0H:%0M:%0S' (datatype=datetime)
;
run;
options tz='America/New_York'; 
data current_datetime;

	currentDtTime=datetime();

   x=dhms(today(),0,0,time());
   format x dtmmddyy.;
   put currentDtTime=dtmmddyy.;
run;

  

Tom
Super User Tom
Super User

You can use PICTURE formats to create many different formats for displaying date, time or datetime in different ways.

But I am curious why you want to use such a confusing format?  If you show dates as numbers in MDY (or DMY) order you will confuse half of your audience and risk misinterpretation of ambiguous values like 10/12/2020 .   

Why not display your dates in YMD order and avoid that issue? 

ballardw
Super User

@Tom wrote:

You can use PICTURE formats to create many different formats for displaying date, time or datetime in different ways.

But I am curious why you want to use such a confusing format?  If you show dates as numbers in MDY (or DMY) order you will confuse half of your audience and risk misinterpretation of ambiguous values like 10/12/2020 .   

Why not display your dates in YMD order and avoid that issue? 


My guess: That is the Excel / Microsoft datetime default display and OP wants that for familiarity.

SAS Innovate 2025: Register Today!

 

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 814 views
  • 1 like
  • 3 in conversation