Usage Note 23639: How can I name my ODS HTML files the same as the values of a variable in my data set?
There is no ODS option to do this, but it can be done with some simple SQL and macro
logic, as in the example code that follows.
We put the distinct levels of a variable into a macro variable and then, with
a WHERE statement, subset the data set based on the value of the variable. The NOTOP
and NOBOT ODS sub-options are used to append the files together.
See SAS Note 23660 for more examples of appending to an HTML file.
Use the code on the Full Code tab to generate RTF files based on the value of a variable. The logic in the Full Code tab applies to any ODS destination.
/* Sample data */
data test;
input x $ y z;
cards;
a 3 4
a 4 4
b 4 5
c 5 6
d 5 5
;
run;
/* Create macro variable last with the distinct number of levels */
/* of variable X. */
proc sql noprint;
select count(distinct x) into :last
from test;
/* Create macro variables VAL1 to VAL4. The ending range gets the */
/* value from macro variable last. */
select distinct(x) into: val1- :val%left(&last)
from test;
run;
quit;
%put _user_;
/* Set up FILENAME statement with the MOD option so that you can */
/* append to it. */
filename cont 'c:\contents.html' mod;
options mprint;
%macro loopit;
%do i = 1 %to &last;
%if &i=1 %then %do;
ods html
frame='c:\myframe.html'(url='myframe.html')
contents=cont(nobot url='contents.html')
body="c:\&&val&i...html"
anchor='reportx';
%end;
%else %if &i ne &last %then %do;
ods html frame='c:\myframe.html'(url="myframe.html")
contents=cont(nobot notop url="contents.html")
body="c:\&&val&i...html"
anchor='reporty';
%end;
%else %if &i = &last %then %do;
ods html frame='c:\myframe.html'(url="myframe.html")
contents=cont(notop url='contents.html')
body="c:\&&val&i...html"
anchor='reportz';
%end;
proc report nowd;
col y z;
define y / group;
where x="&&val&i";
title "this is a is for &&val&i";
run;
%end;
ods html close;
%mend loopit;
options mprint;
%loopit
dm 'wbrowse "c:\myframe.html"';
Operating System and Release Information
*
For software releases that are not yet generally available, the Fixed
Release is the software release in which the problem is planned to be
fixed.
The sample code creates RTF files based on the value of the variable STATE. The code results in files MA.RTF, MD.RTF and VA.RTF.
data one;
input state $ age;
datalines;
VA 21
VA 23
MD 23
MD 12
MA 12
MA 34
;
run;
%macro test(value);
ods rtf body="&value..rtf";
proc print data=one(where=(state="&value"));
run;
ods rtf close;
%mend;
proc sort ;
by state;
run;
data _null_;
set one;
by state;
if first.state then
call execute('%test('||state||')');
run;
Type: | Usage Note |
Priority: | low |
Topic: | SAS Reference ==> ODS (Output Delivery System) Third Party ==> Output ==> HTML
|
Date Modified: | 2004-01-16 14:38:15 |
Date Created: | 2004-01-06 14:38:29 |