SAS supports a number of ISO formats for datetimes that are common to transaction logs, web logs, XML, and JSON, and other interchanges.
Here's an example from the documentation (linked above):
data _null_;
input dtB :b8601dt15. dtE :e8601dt19.;
put dtB=b8601dt. dtE=e8601dt.;
datalines;
20120402T124022 2012-04-02T12:30:22
;
run;
Output:
dtB=20120402T124022 dtE=2012-04-02T12:30:22
Usually one of those formats will suit, as you're trying to conform to another standard.
However, you discovered that you can create your own custom datatime format like this:
proc format; picture BI_DTIME_FMT other = '%Y%0m%0d %0H:%0M:%0S' (datatype=datetime); run; data _null_; /*sampdtime=1551022320;*/ sampdtime='23FEB2009:15:32:00'dt; put sampdtime= BI_DTIME_FMT.; run;
To make that format "permanent", place it in a libname that is found in your OPTIONS FMTSEARCH path.
Hi,
Some good suggestions above. For cahnging the underlying value to a specific format, I normally use the nldate, nltime or nldatm functions. For the format I would use the suggestion as above.
proc format;
picture ymdH24MS
other = '%Y-%0m-%0d %0H:%0M:%0S' (datatype=datetime);
run;
data tmp;
x=datetime();
format x ymdH24MS.;
y=nldatm(x, '%Y-%m-%d %H:%M:%S');
run;
SAS supports a number of ISO formats for datetimes that are common to transaction logs, web logs, XML, and JSON, and other interchanges.
Here's an example from the documentation (linked above):
data _null_;
input dtB :b8601dt15. dtE :e8601dt19.;
put dtB=b8601dt. dtE=e8601dt.;
datalines;
20120402T124022 2012-04-02T12:30:22
;
run;
Output:
dtB=20120402T124022 dtE=2012-04-02T12:30:22
Usually one of those formats will suit, as you're trying to conform to another standard.
However, you discovered that you can create your own custom datatime format like this:
proc format; picture BI_DTIME_FMT other = '%Y%0m%0d %0H:%0M:%0S' (datatype=datetime); run; data _null_; /*sampdtime=1551022320;*/ sampdtime='23FEB2009:15:32:00'dt; put sampdtime= BI_DTIME_FMT.; run;
To make that format "permanent", place it in a libname that is found in your OPTIONS FMTSEARCH path.
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.
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.