Does your SAS code know what time it is? Add a timestamp.
In 1986 the Beastie Boys released their classic debut album, License to Ill, and the last track posed a question: “What’s the time?” The Beasties answered with an anthem, “It’s time to get ill.” I think Peter Crawford, SAS programmer extraordinaire, would have answered more simply. What time is it? It’s %now.
%Now – a Timestamp Macro
%Now generates a timestamp. It’s a simple SAS macro, but despite its simplicity, it has a lot to teach about macro design. In fact, Peter wrote an entire paper about the macro, so I won’t repeat the lessons.
The macro is:
%MACRO now( fmt= DATETIME23.3 ) /DES= 'timestamp' ; %SYSFUNC( DATETIME(), &fmt ) %MEND now ;
It’s a utility macro, and I have it in my autocall library, so that it’s always there when I want it.
I often use it in footnotes. This code snippet:
Will produce a footnote with a timestamp in it:
I also add timestamps to file names. Here, I add a timestamp to the log file from a nightly job. The default format (DATETIME23.3) is fine for a footnote. For file names, I typically format the timestamp as YYYYMMDDThhmmss, which maintains readability and also sorts in chronological order.
I’ve written before about macro utilities, and about minimalist programming, and %Now combines both of those interests. %Now has a special place in my heart, since it is the first one-liner I learned, and it helped me realize the purpose of the macro language. Other useful one-liners I’ve seen include %isblank and %age.
You can learn more about SAS Business Intelligence from the "SAS BI Bible." Take a peek inside the Building Business Intelligience with SAS book.
Latest posts by Quentin McMullen (see all)
- Are you looking at the world through BI Glasses? - November 13, 2013
- Taming SAS Stored Process Selection List Prompts - August 7, 2013
- Using an Autocall Macro Library in SAS BI - July 10, 2013
- These are a Few of My Favorite Things… about the SAS Enterprise Guide Program Editor - March 27, 2013
- PC SAS Programmer Facing UNIX? SAS Enterprise Guide to the Rescue - March 20, 2013