The SAS Output Delivery System and reporting techniques

ODS Proc Print HTML

Reply
N/A
Posts: 0

ODS Proc Print HTML

I am using ODs to create multiple versions of a proc report based on page break using the newfile=page option. Currently the files are consectuvely numbered, is there a way to name the files based on the page break value as part of the output file name?
SAS Super FREQ
Posts: 8,740

Re: ODS Proc Print HTML

Hi:
The way that NEWFILE= option works is by consecutively numbering the output files created. The only ways for you to control the naming used would be
1) from within a SAS macro program that would generate a unique name (based on your specification) for every value of the page variable or
2) to collect the names by piping a DIR to a file and then do an X command or SYSTASK command and rename the numbered files after they are created (this means you will have to know what value is associated with what number).

A third possibility might be to create your output using PROC REPORT with BY groups and then use ODS DOCUMENT and PROC DOCUMENT to replay the BY groups to file names of your choosing. If you just use PROC REPORT and PAGE processing, you do not get separate output objects that are replayable, but with BY group processing, you can generate separate output objects that will be replayable, as shown in the program below (based on an example from my SGF paper)
http://support.sas.com/resources/papers/proceedings10/084-2010.pdf

cynthia
[pre]
proc sort data=sashelp.prdsale out=prdsale;
by Country region prodtype;
run;

title; footnote;
ods document name=work.prddoc(write);
proc report data=prdsale nowd;
column country region prodtype predict actual;
by country;
define country / group;
define region / group;
define prodtype / group;
define predict / mean 'Average Predict';
define actual / mean 'Average Actual';
break after country / page summarize;
run;
ods document close;

proc document name=work.prddoc;
list / levels=all;
run;
quit;

** to use this REPLAY syntax, you need SAS 9.2;
** this replay process could be macro-ized;
** Replay Using a BY variable name;
ods html file='c:\temp\canada.html' style=sasweb;
proc document name=work.prddoc;
replay ^(where=(Country = 'CANADA')) ;
run;
quit;
ods _all_ close;

ods html file='c:\temp\germany.html' style=sasweb;
proc document name=work.prddoc;
replay ^(where=(Country = 'GERMANY')) ;
run;
quit;
ods _all_ close;

ods html file='c:\temp\usa.html' style=sasweb;
proc document name=work.prddoc;
replay ^(where=(Country = 'U.S.A.')) ;
run;
quit;
ods _all_ close;
[/pre]
N/A
Posts: 0

Re: ODS Proc Print HTML

Hi Cynthia

I like option 1

1) from within a SAS macro program that would generate a unique name (based on your specification) for every value of the page variable or

Do you have a example of how to do this? As long as I can put the unique page variable in the file name somewhere that would work very well
SAS Super FREQ
Posts: 8,740

Re: ODS Proc Print HTML

Hi:
Essentially, you will need to use a WHERE statement for each value of your PAGE variable. The program below shows a simple example. With more advanced programming and macro techniques, you could automate the creation of the list of "page" variables and would not need to invoke the macro multiple times for every unique value of the page variable.

There are a lot of previous forum postings on using SAS Macro processing and lots of good user group papers on doing things like this (automating a process). Here are some links to papers to get you started:
http://www2.sas.com/proceedings/sugi28/056-28.pdf
http://www.ats.ucla.edu/stat/sas/library/nesug99/bt046.pdf
http://www2.sas.com/proceedings/sugi30/028-30.pdf
http://www2.sas.com/proceedings/sugi30/130-30.pdf
http://support.sas.com/resources/papers/proceedings10/142-2010.pdf
http://www.gasug.org/papers/DemystifyingMacro_Fecht.pdf
http://www2.sas.com/proceedings/sugi24/Coders/p087-24.pdf
http://www2.sas.com/proceedings/sugi28/090-28.pdf
http://ndc.mayo.edu/mayo/research/biostat/sasmacros.cfm

cynthia
[pre]
proc sort data=sashelp.prdsale out=prdsale;
by Country region prodtype;
run;

** define macro program...with parameters for;
** Country and Filename to be used;
** Note how ODS HTML step is INSIDE the macro program;
** so the FNAME macro variable can be used to create the file name;
%macro docntry(cntry=, fname=);
ods listing close;
ods html file="c:\temp\&fname..html" style=sasweb;

proc report data=prdsale nowd;
where country = "&cntry";
column country region prodtype predict actual;
title "For country: &cntry";
define country / group;
define region / group;
define prodtype / group;
define predict / mean 'Average Predict';
define actual / mean 'Average Actual';
break after country / page summarize;
run;

ods _all_ close;

%mend docntry;

** Now invoke the macro program to generate code and send;
** the generated code to the SAS compiler;
** A more automated approach could be achieved with more sophisticated;
** macro techniques and programming.;
%docntry(cntry=GERMANY, fname=ger);
%docntry(cntry=CANADA, fname=can);
%docntry(cntry=U.S.A., fname=usa);
[/pre]
Ask a Question
Discussion stats
  • 3 replies
  • 137 views
  • 0 likes
  • 2 in conversation