Proc report used in SAS for enhancing the appearance of the report with Output. It is one of the most important procedures with wide scope. Wide range of options can be used in this procedure to vary the output. Even ODS and compute block can be used with this procedure.
2. OVERVIEW
Purpose
Common Features with others
Syntax
Types of Reports
Column statement
Define statement & its options
Text Wrapping
Break and rbreak statements
Compute Block
ODS
3. PURPOSE
Control the appearance of every column
Summary reports
Detail listings
Multiple-panel reports
Text wrapping within a column
4. SHARES FEATURES WITH
Proc print : Customizes the output
Proc means : Produce Statistics
Proc tabulate : Create Summary table
Proc sort : Sort the observations
Data step : Create new variable
5. SYNTAX
proc report data=libref.dataset-name;
run;
The Report is always generated in separate
interactive window namely Proc REPORT.
The generate the report in Output window we use
special keywords namely
nowd or nowindows - Windows OS
11. title ‘Column statement for Summary report';
proc report data = sashelp.class nowd;
column age height weight;
run;
12. RENAMING THE VARIABLE
title 'Display usage';
proc report data = sashelp.class nowd;
column age height sex weight;
define height / display width = 6;
define age /display width= 5;
define sex /display "gender" width = 6;
run;
13.
14. GROUP OPTION
title 'Demonstrating GROUP usage';
proc report data = sashelp.class nowd;
column sex height weight;
define sex / group width =11;
define height /analysis mean "Average height" width=12 ;
define weight /analysis mean "Average weight" width=12;
run;
15.
16. *Creating new variable Comment and adding observations to it using else if conditions;
data class1;
set sashelp.class;
if age=11 then Comment='need two more years to reach 13 and three more years to reach 14';
else if age=12 then Comment='need two more years to reach 14 and three more years to reach 15';
else if age=13 then Comment='need two more years to reach 15 and three more years to reach 16';
else if age=14 then Comment='need two more years to reach 16';
else if age=15 then Comment='need one more year to reach 16';
else if age=16 then Comment='the oldest candidate among all of them';
run;
title 'Creating new variable Comment and adding observations to it using else if conditions';
proc print data=class1;
run;
17.
18. TEXT WRAPPING
title 'Flow option for text wrapping';
proc report data=class1 nowd headline split=' ' ls=100;
column name age sex height weight comment;
define name / "Candidate name" width=10;
define age / width=3;
define sex / "Gender" width=6;
define height / "Candidate height" width=10;
define weight / "Candidate weight" width=10;
define comment / width=30 flow;
run;
19.
20. MULTIPLE GROUP USAGE
title 'Demonstrating MULTIPLE GROUP usage';
proc report data = class1 nowd headline;
column sex age comment weight;
define sex / group width=11;
define age / group width=8;
define comment / width=40 flow;
define weight / analysis mean "Average weight" width=12 ;
run;
21.
22. SORTING & JUSTIFICATION
title 'Sorting using Order in Proc report';
proc report data=class1 nowd;
column age name sex;
define age/order "candidate age" width=20 right;
define name/ "candidate name" width=14 left;
define sex/ "Gender" width=6 center;
run;
23.
24. MULTIPLE ORDER
title 'Multiple order usage' ;
proc report data=class1 nowd;
column name age weight;
define name/ "candidate name" width=14;
define age/ order "candidate age" width=20;
define weight/ descending order width=6 format=6.;
run;
28. PRODUCING REPORT BREAKS
The proc report produces totals and sub-totals using
BREAK
RBREAK
Following the keyword, location is given either AFTER or
BEFORE.
Options
OL
UL
DOL
DUL
Word SUMMARIZE is used for analysis of the statistic in
define statement.
29. SUPPRESS OPTION
title "Demonstrating BREAK usage";
proc report data=sashelp.class nowd headline;
columns name height age weight;
define age/ display order width=8;
define name / display width=8;
define height / display width=7;
define weight / sum width=7;
break after age / ol dul summarize;
run;
30.
31. BREAK STATEMENT
title "Demonstrating BREAK usage";
proc report data = sashelp.class nowd headline;
columns age name height weight;
define age / display order width=8;
define name / display width=8;
define height/ display width=7;
define weight / sum width=7;
break after age/ ol dul summarize suppress;
run;
32.
33. RBREAK
title "Producing report breaks using RBREAK";
proc report data=sashelp.class nowd headline;
columns name height weight;
define name /display width=8;
define height/display width=7;
define weight/ display "Balance" width=7 format=dollar5.;
rbreak after / ol ul summarize;
run;
34.
35. COMPUTE BLOCK
To create a Compute block, COMPUTE and ENDCOMP
statements are used.
A programming logic is included in the computing block.
Prior to compute block, the keyword Computed must be
used in the define statement based on which variable we
create a new variable.
Example: compute new-variable;
new-variable=formula with old-variable;
endcomp;
36. COMPUTING A NEW VARIABLE
title "Computing a new Variable";
proc report data=sashelp.class nowd;
column name weight wtkg;
define name/display "Candidate name" width=12;
define weight/display "Weight in pounds" width=12;
define Wtkg/computed "Weight in kg" width=10 format=6.1;
compute Wtkg;
Wtkg=weight/2.2;
endcomp;
run;
37.
38. NOPRINT
title "Computing a new Variable";
proc report data=sashelp.class nowd headskip;
column name weight wtkg;
define name/display "Candidate name" width=12;
define weight/display "Weight in pounds" noprint width=12;
define Wtkg/computed "Weight in kg" width=10 format=6.1;
compute Wtkg;
Wtkg=weight/2.2;
endcomp;
run;
39.
40. COMPUTE BLOCK FOR CHARCTER VARIABLE
title "Creating a Character variable in a Compute block";
proc report data=sashelp.class nowd;
columns name height height_status;
define name/ display "Candidate name" width=6;
define height/display width=6;
define height_status/ computed "height_status" width=18;
compute height_status/ character length=14;
if height le 59 then height_status='short';
else if height gt 64 then height_status='tall';
else if height then height_status='Medium';
endcomp;
run;
44. ACROSS
title 'Summary Report';
proc report data=sashelp.prdsale nowd;
column country product region,('Sales' predict actual);
define country /group;
define product /group;
define region /across ;
define predict / sum 'Predicted';
define actual /sum 'Actual';
rbreak after / summarize;
run;
45.
46. OUTPUT DELIVERY SYSTEM
title 'Proc Report using ODS';
ods pdf style = default
body = 'sashelp.prdsale1.pdf';
proc report data=sashelp.prdsale nowd headline ;
column region country product,actual totalsales;
define region / group;
define country / group;
define product / across "-Product-";
define actual / analysis sum format = dollar8. 'Sales';
define totalsales / computed format = dollar10.'Total Sales';
break after region /ol ul summarize suppress;
rbreak after / dul summarize;
compute totalsales;
totalsales = sum(_c3_,_c4_,_c5_,_c6_);
endcomp;
run;
ods pdf close;