The SAS Output Delivery System and reporting techniques

Display a SAS date in Proc Template

Not applicable
Posts: 0

Display a SAS date in Proc Template

I am trying to autmate a report, and need to put in an As of date, the date keeps showing up as a non formatted SAS date. Any help is much appreciated.
Posts: 9,371

Re: Display a SAS date in Proc Template

Posted in reply to deleted_user
Are you using proc template for style templates or for table templates or for tagset templates?
Not applicable
Posts: 0

Re: Display a SAS date in Proc Template

Posted in reply to Cynthia_sas
I am using for table templates
Posts: 9,371

Re: Display a SAS date in Proc Template

Posted in reply to deleted_user
Here's an example of using a date 3 different ways in a table template:
1) from a user-defined macro variable (MYDATE)
2) from a system macro variable (SYSDATE9)
3) from a data step variable (BYEAR and BDAY)
ods path work.templat(update)

proc template;
define table wombat;
mvar mydate sysdate9;

column name age byear bday;
header h1;
define header h1;
text "This is from a user macro var: " mydate;
define footer f1;
text "This is from an automatic macro var: " sysdate9;
define name;
define byear;
header='Approx Birth Year';
define bday;
header='Unformatted Date';


%let mydate = %sysfunc(today(),mmddyy10.);

ods listing close;
ods html file='c:\temp\testdate.html' style=sasweb;
data _null_;
set sashelp.class;
byear = today() - round(age*365.25);
bday = today() - round(age*365.25);
file print ods=(template='wombat');
put _ods_;
ods html close;

The way that today() is formatted for the header is with a %sysfunc that uses the mmddyy10. format for the number returned from the TODAY function. The SYSDATE9 macro variable is already formatted. So the way that both of those are referenced in the table template is through the use of the MVAR statement -- which lets the table template know that it has to go out and get the value from the global symbol table WHEN the table template is bound to the data. Or, if you just want some date value NOT calcuated by SAS, then you could change the %LET statement to be:
%let mydate = November 30, 2006;

On the other hand, the data variables BYEAR and BDAY appear in the data and I could either set the format in the data step or I could set the format in the table template with the FORMAT= statement (which is what I show). If you uncomment the FORMAT= statement for BDAY, you will see a formatted date when you rerun the program.

I picked a table template to use with a DATA Step program, just because it was easier to create date variables using SASHELP.CLASS. If you are modifying a procedure template to have an AS OF date, then the MVAR method is probably the one you want to use. If you want to use a data step or data set variable in a header or footer, then your data step program would need to get a bit more complicated, but that also is do-able.

If you need more help with constructing your table template, Tech Support is an excellent resource. You can find out how to contact them here:
Ask a Question
Discussion stats
  • 3 replies
  • 2 in conversation