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!
proc sql noprint;
select distinct year
into :year1 - :year99
from sashelp.orsales;
%let yearcnt = &sqlobs;
quit;
1
PROC 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!
ods html style=default
path="&path\results"
body='E8_4b.html';
title1 'Total profit per year';
/* ... titres ... */
proc report data=sashelp.orsales nowd split='*';
column year product_line profit;
define year / group;
define product_line
/ group
'Product*Groups';
define profit / analysis
sum format=dollar15.2
'Annual*Profit';
break after year / summarize suppress skip;
rbreak after / summarize ;
compute before year;
yr = year;
endcomp;
compute product_line;
* For SPORTS create a link;
if product_line = 'Sports' then do;
link = 'Sports'||trim(left(put(yr,4.)))||'.html';
call define(_col_, 'url', link);
end;
endcomp;
run;
ods _all_ close;
1
ods html style=default
2
path="&pathesults"
3
body='E8_4b.html';
4
5
title1 'Total profit per year';
6
/* ... titres ... */
7
8
PROC REPORTDATA=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'THENDO;
26
link = 'Sports'||trim(left(put(yr,4.)))||'.html';
27
call define(_col_, 'url', link);
28
END;
29
endcomp;
30
RUN;
31
32
ods _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!
%do yr = 1 %to &yearcnt;
* Sports Detail Report for &&year&yr;
ods html style=default
path="&path\results"
body="Sports&&year&yr...html";
title2 "Sports Detail for &&year&yr";
title3 "<a href='E8_4b.html'>Return to Full Report<a>";
proc report data=sashelp.orsales(where=(product_line='Sports' & year=&&year&yr))
nowd split='*';
column product_category profit;
/* ... définitions colonnes ... */
rbreak after / summarize ;
run;
ods _all_ close;
%end;
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>";
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.
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. WeAreCAS is an independent community site and is not affiliated with SAS Institute Inc.
This site uses technical and analytical cookies to improve your experience.
Read more.