Tuesday, October 17, 2017

Hack 6.4 Inserting the SAS Date and Time into an RTF Document



SAS Programming Professionals,

Did you know that you can insert the standard SAS date and time into a new RTF document in place of the default RTF specification that inserts the printing date and time?

This is a bit hard to visualize, but stick with me; it’s worth it! 

If you were to submit the follow simple program at 8:00am this morning:

ods rtf file="rtfdate2.rtf";

proc print data=sashelp.class;
run;

ods rtf close;

…you would create an RTF document that would have the date/time embedded as a header in the upper right hand side.  If you were to open that file at 11:00am this morning, the header would read:

11:00 Monday, December 12, 2015  1

…even thought it was actually created at 8:00am this morning.  If you were to print the document at 11:30 this morning, the header on the printed page would read:

11:30 Monday, December 12, 2015  1

…even though it was actually created at 8:00am this morning and you opened the file at 11:00am this morning. 

Now, what’s wrong with this picture?  Well, nothing if you want the RTF default header date/time in effect.  However, if you want to document the date/time this document was actually created, then code the SASDATE option in the ODS statement.  Here is an example using the same program as before:

ods rtf file="sasdate.rtf" sasdate;

proc print data=sashelp.class;
run;

ods rtf close ;

If you were to submit that at 8:00am this morning, then whenever you open it up, you will see the following header:

8:00 Monday, December 12, 2015  1

Similarly, whenever you print the document, that will be the header in the hard copy.  This will happen each and every time that you open the file and that you print the file.

So, the SASDATE option on the ODS FILE= statement “freezes” the date/time the RTF document was created.  Nine times out of ten, that is exactly the behavior that I want!  And you?

Best of luck in all your SAS endeavors!


---MMMMIIIIKKKKEEEE
(aka Michael A. Raithel)
Author of the new cult classic for computer programmers:  It Only Hurts When I Hit <ENTER>
Print edition:  http://tinyurl.com/z8bzx2e 
Kindle edition: http://tinyurl.com/zypgqa7 

The hack above is an excerpt from the book:  Did You Know That?  Essential Hacks for Clever SAS Programmers

No comments:

Post a Comment