DATA Step, Macro, Functions and more

want to add a date to my ODS HTML text

Reply
Regular Contributor
Posts: 229

want to add a date to my ODS HTML text

%global datim = datetime();
%put &datim;
ods html file="/imec/other/imecweb/osp/fab300/test/shift_reports/PrioLotReport.html" (title="Prio Lot Report") stylesheet=(URL="http://imecwww.imec.be/~osp/fab300/test/ImecStyle.css");
ods listing close;
ods escapechar='^';
/* title */
ods html text='^S={just=c font_size=15pt foreground=black} Prio Lot Report - Last Run on &datim ^S={}';

but &datim shows as &datim, any solutions?
Super Contributor
Posts: 394

Re: want to add a date to my ODS HTML text

Enclose the text in quotes instead of apostrophes. SAS does not resolve macro variables within apostrophes.
Super Contributor
Posts: 273

Re: want to add a date to my ODS HTML text

Apparently more unclear Tim

[pre]
%global datim= %sysfunc(compress(%sysfunc(datetime(),IS8601DT.), -Smiley Happy);
%global dati = datetime();
%put &datim;%put &dati;
ods listing close;
ods html file="d:\temp\PrioLotReport.html" (title="Prio Lot Report") ;
ods escapechar='^';
/* title */
*ods html text="^S={just=c font_size=15pt foreground=black} Prio Lot Report - Last Run on &datim &dati ^S={}";
ods html text="Prior Lot Report - Last Run on %sysfunc(datetime()) &sysdate
&datim &dati ";
proc print data=sashelp.class(obs=1);run;
ods html close;


[/pre]

Is it more specifically a problem of how the ods clothing is working and
WHEN is it passing the chain to the ods construct ?

In my test the direct datetime and sysdate are resolved but not the macros variables

Andre
Super Contributor
Posts: 394

Re: want to add a date to my ODS HTML text

The ODS statement is no different than any other statement. The macro processor runs before the ODS statement is executed. The ODS statement gets the text that the macro processor produced. I ran your test:

[pre]
%global datim;
%let datim = %sysfunc(compress(%sysfunc(datetime(),IS8601DT.), -Smiley Happy);
%global dati;
%let dati = datetime();
%put &datim;%put &dati;
ods listing close;
ods html file="PrioLotReport.html" (title="Prio Lot Report") ;
ods escapechar='^';
/* title */
*ods html text="^S={just=c font_size=15pt foreground=black} Prio Lot Report - Last Run on &datim &dati ^S={}";
ods html text="Prior Lot Report - Last Run on %sysfunc(datetime()) &sysdate &datim &dati ";
proc print data=sashelp.class(obs=1);run;
ods html close;
[/pre]

The text in the HTML file is:
Prior Lot Report - Last Run on 1614686110.021 02MAR11 20110302T115509 datetime()
Super Contributor
Posts: 273

Re: want to add a date to my ODS HTML text

You are right, Tim
I think i was perhaps opening the wrong html file on my pc without reading carefully the log.
In fact rereading the code
i reproduce the problem i have encounter
when based too quickly upon the initial %global statement
i did not apply the correct syntax
%global datim; for defining the status of a macro variable
and then only after
%let datim=
with the definition of the content.
%global datim= genders errors in the log
Sorry
Andre Message was edited by: Andre
Regular Contributor
Posts: 229

Re: want to add a date to my ODS HTML text

thanks, it is working
Valued Guide
Posts: 2,174

Re: want to add a date to my ODS HTML text

> %global datim = datetime();

is this expecting %global to assign a value?
sorry, it doesn't work that way.
the above syntax generates an ERROR: pointing to the '=' in my SAS9.2

you need %LET datim = something ;
Ask a Question
Discussion stats
  • 6 replies
  • 263 views
  • 0 likes
  • 4 in conversation