SAS provides a number of tools to include the date and/or time in the generated output. I like to include the values in a footnote and use the %sysfunc function to get the current date and/or time. And, of course, for the sake of consistency and ease of use, I package this code as a macro.
Here is a sample macro:
%local dt tm;
%if %superQ(datefmt) ne %then %let dt = %sysfunc(date(),&datefmt);
%if %superQ(timefmt) ne %then %let tm = %sysfunc(time(),&timefmt);
&text &tm &separator &dt
The macro generates text that can be used in a title or footnote statement; or even in a put statement. This version of the macro allows you to specifiy:
- text: the text to display before the date/time
- datefmt: the SAS date format to use for the date format. If a null/blank value is specified, the date is not included
- timefmt: the SAS time format to use for the time format. If a null/blank value is specified, the time is not included
- separator: the text to separate the date and time display
Now all I have to do is include the macro call in, for example, a footnote statement:
proc print data = sashelp.class;
title 'The ever popular CLASS data set';
footnote j=right h=1 "%generatedAt";
Note the user of the j (justify) and h (height) attributes. Check out Controlling text height in titles and footnotes for some other examples of controlling the format in title and footnote statements.