SAS Bits & Pieces
Here’s a few SAS bits and pieces which may be useful.
PROC FORMAT Date/Time Directives
A previously undiscovered feature of SAS (they seem to have snuck it in around version 6 without putting it in the list of new features, which all dedicated computer geeks read when upgrading), is the ability to create your own date/time/datetime formats.
Witness the following:
proc format; picture td (default=80) other='It''s %A, the %d of %B, year of our lord %Y' (datatype=date); data _null_; a=today(); put "Tom's date: " a td.-l; run;
Tom's date: It's Wednesday, the 11 of October, year of our lord 2000
Note the single quotes when creating the format to avoid triggering the macro language. The ‘-l’ in the put statement left-aligns it.
Note also specifying a default length for the format. Stupidly, SAS defaults to the length of the string specified, not the resulting length after the directives have been expanded.
See PROC FORMAT → PICTURE statement, for the various directives available and more information.
ISO 8601 Date/Time Support
Another obscurely documented feature is support for ISO 8601 date formats—buried under Base SAS → SAS XML LIBNAME Engine User’s Guide → Appendixes → ISO 8601 SAS Formats and Informats.
data _null_; datetime=datetime(); put datetime=is8601dt.; time=time(); put time=is8601lz.; run;
Available from at least version 8.