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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.