The Output Delivery System opens up great possibilities for sharing generated reports. To increase the flexibility of the reports generated by, for example the ODS HTML output, use the ODS TEXT= option to add text blocks between report items.
When using this feature in the HTML destination, some knowledge of HTML tags is necessary.
Dynamic content can be used by retrieving information from the Dictionary Tables and storing results in a macro variable:
proc sql noprint ; select name into :htmlvarlist separated by '<br/>' from dictionary.columns where libname = 'SASHELP' and memname = 'CLASS' ; quit ; %put &htmlvarlist ;
Looking at the stored value:
Name<br/>Sex<br/>Age<br/>Height<br/>Weight
The <br/> tag is rendered in a browser as a Line Break. Including this macro variable in an HTML report:
ods html ; proc print data = sashelp.class ; run ; ods text= "<p>The following variables exist in the SASHELP.CLASS dataset:</p> <p>&htmlvarlist</p>" ; proc means data = sashelp.class mean ; class sex ; var age ; run ; ods html close ;
Generates the following result:
Obs | Name | Sex | Age | Height | Weight |
---|---|---|---|---|---|
1 | Alfred | M | 14 | 69.0 | 112.5 |
2 | Alice | F | 13 | 56.5 | 84.0 |
3 | Barbara | F | 13 | 65.3 | 98.0 |
4 | Carol | F | 14 | 62.8 | 102.5 |
5 | Henry | M | 14 | 63.5 | 102.5 |
6 | James | M | 12 | 57.3 | 83.0 |
7 | Jane | F | 12 | 59.8 | 84.5 |
8 | Janet | F | 15 | 62.5 | 112.5 |
9 | Jeffrey | M | 13 | 62.5 | 84.0 |
10 | John | M | 12 | 59.0 | 99.5 |
11 | Joyce | F | 11 | 51.3 | 50.5 |
12 | Judy | F | 14 | 64.3 | 90.0 |
13 | Louise | F | 12 | 56.3 | 77.0 |
14 | Mary | F | 15 | 66.5 | 112.0 |
15 | Philip | M | 16 | 72.0 | 150.0 |
16 | Robert | M | 12 | 64.8 | 128.0 |
17 | Ronald | M | 15 | 67.0 | 133.0 |
18 | Thomas | M | 11 | 57.5 | 85.0 |
19 | William | M | 15 | 66.5 | 112.0 |
The following variables exist in the SASHELP.CLASS dataset:
Name
Sex
Age
Height
Weight
Analysis Variable : Age | ||
---|---|---|
Sex | N Obs | Mean |
F | 9 | 13.2222222 |
M | 10 | 13.4000000 |
Extending this logic any html tags can be incorporated, so instead of using the <br/> it is possible to generate bullet points with the <li> tag:
proc sql noprint ; select name into :htmlvarlist separated by '</li><li>' from dictionary.columns where libname = 'SASHELP' and memname = 'CLASS' ; quit ;
Which generates the snippet:
Name</li><li>Sex</li><li>Age</li><li>Height</li><li>Weight
Then include the resultant code snippet within either an Ordered (number) or Unordered (bullet) list:
ods text= "<p>The following variables exist in the SASHELP.CLASS dataset:</p> <ul><li>&htmlvarlist</li></ul>" ;
Which renders as:
The following variables exist in the SASHELP.CLASS dataset:
- Name
- Sex
- Age
- Height
- Weight