BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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.
Thanks
3 REPLIES 3
Cynthia_sas
SAS Super FREQ
Are you using proc template for style templates or for table templates or for tagset templates?
deleted_user
Not applicable
I am using for table templates
Cynthia_sas
SAS Super FREQ
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)
[pre]
ods path work.templat(update)
sashelp.tmplmst(read);

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;
end;
define footer f1;
text "This is from an automatic macro var: " sysdate9;
end;
define name;
header='Name';
end;
define byear;
header='Approx Birth Year';
format=year4.;
end;
define bday;
header='Unformatted Date';
**format=mmddyy10.;
end;


end;
run;

%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_;
run;
ods html close;
[/pre]

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:
http://support.sas.com/techsup/contact/index.html
cynthia

sas-innovate-2024.png

Today is the last day to save with the early bird rate! Register today for just $695 - $100 off the standard rate.

 

Plus, pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 803 views
  • 0 likes
  • 2 in conversation