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.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.