Published on :
Reporting SASHELP

Automated Generation of Linked HTML Reports with Navigation

This code is also available in: Deutsch Español Français
The script defines a '%linked' macro that automates the creation of a main report and multiple detailed sub-reports. It uses PROC SQL to dynamically identify available years in the data. The main report contains hyperlinks (drill-down) specifically for the 'Sports' product line, leading to detailed HTML files iteratively generated for each year via a macro loop.
Data Analysis

Type : SASHELP


The data comes from the standard 'sashelp.orsales' table. No external data is required.

1 Code Block
PROC SQL
Explanation :
Retrieves the distinct list of years present in the 'sashelp.orsales' table and stores these values in a series of macro variables (:year1, :year2...) to drive the subsequent generation loop.
Copied!
1PROC SQL noprint;
2 select distinct year
3 into :year1 - :year99
4 from sashelp.orsales;
5 %let yearcnt = &sqlobs;
6 QUIT;
2 Code Block
PROC REPORT
Explanation :
Generates the main summary report. Uses a 'COMPUTE' block to dynamically construct a URL (drill-down link) when the product line is 'Sports', pointing to the detailed report for the corresponding year.
Copied!
1ods html style=default
2 path="&pathesults"
3 body='E8_4b.html';
4 
5title1 'Total profit per year';
6/* ... titres ... */
7 
8PROC REPORT DATA=sashelp.orsales nowd split='*';
9 column year product_line profit;
10 define year / group;
11 define product_line
12 / group
13 'Product*Groups';
14 define profit / analysis
15 sum FORMAT=dollar15.2
16 'Annual*Profit';
17 break after year / summarize suppress skip;
18 rbreak after / summarize ;
19 
20 compute before year;
21 yr = year;
22 endcomp;
23 compute product_line;
24 * For SPORTS create a link;
25 IF product_line = 'Sports' THEN DO;
26 link = 'Sports'||trim(left(put(yr,4.)))||'.html';
27 call define(_col_, 'url', link);
28 END;
29 endcomp;
30 RUN;
31 
32ods _all_ close;
3 Code Block
PROC REPORT
Explanation :
Macro loop iterating over each detected year. For each year, it generates a distinct HTML file containing the profit details for the 'Sports' category, filtered via a dynamic WHERE clause.
Copied!
1%DO yr = 1 %to &yearcnt;
2 * Sports Detail Report for &&year&yr;
3 ods html style=default
4 path="&pathesults"
5 body="Sports&&year&yr...html";
6 
7 title2 "Sports Detail for &&year&yr";
8 title3 "<a href='E8_4b.html'>Return to Full Report<a>";
9 
10 PROC REPORT DATA=sashelp.orsales(where=(product_line='Sports' & year=&&year&yr))
11 nowd split='*';
12 column product_category profit;
13 /* ... définitions colonnes ... */
14 rbreak after / summarize ;
15 RUN;
16 
17 ods _all_ close;
18%END;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.