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
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;
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?
@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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.
Ready to level-up your skills? Choose your own adventure.