*Copyright @ www.mycsg.in;
What does PROC REPORT do
`proc report` is used to create tabular reports from SAS datasets
It can display all variables, selected variables, grouped summaries, and customised layouts
In this introductory lesson, we focus on basic reporting behaviour in the listing destination
As you review each example, compare the report output with the output dataset created by `out=`
Create a sample dataset
We copy `sashelp.class` into a WORK dataset named `class`
This gives us a stable dataset for the reporting examples that follow
data class; set sashelp.class; run;
Copy Code
View Log
SAS Log
data class; set sashelp.class; run; NOTE: There were 19 observations read from the data set SASHELP.CLASS. NOTE: The data set WORK.CLASS has 19 observations and 5 variables. NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.00 seconds
The dataset `class` is now available in the `WORK` library
Inspect the data and confirm that it contains the student-level variables from `sashelp.class`
View Data
Dataset View
Display all variables in the dataset
When no `columns` statement is used, `proc report` displays all variables from the input dataset
`nowindows` runs the procedure without the interactive report window
`out=report_all` stores the generated report data in an output dataset
This is a good starting point because it shows the default report behaviour
proc report data=class nowindows out=report_all; run;
Copy Code
View Log
SAS Log
proc report data=class nowindows out=report_all; run; NOTE: There were 19 observations read from the data set WORK.CLASS. NOTE: The data set WORK.REPORT_ALL has 19 observations and 6 variables. NOTE: PROCEDURE REPORT used (Total process time): real time 0.01 seconds cpu time 0.01 seconds
The report output displays the variables present in `class`
The dataset `report_all` stores the report rows created by the procedure
Compare `report_all` with `class` to understand how PROC REPORT represents detail rows
View Data
Dataset View
Display only selected variables
The `columns` statement controls which variables appear in the report and in what order
Here we request only `name`, `sex`, and `age`
This is useful when the input dataset contains many variables but only a few should be shown
proc report data=class nowindows out=report_selected; columns name sex age; run;
Copy Code
View Log
SAS Log
proc report data=class nowindows out=report_selected; columns name sex age; run; NOTE: There were 19 observations read from the data set WORK.CLASS. NOTE: The data set WORK.REPORT_SELECTED has 19 observations and 4 variables. NOTE: PROCEDURE REPORT used (Total process time): real time 0.01 seconds cpu time 0.00 seconds
The report shows just the requested variables
The output dataset also reflects the selected report structure
Verify that variables not listed on the `columns` statement do not appear in the report output
View Data
Dataset View
What happens when only numeric variables are reported
When the report contains only numeric analysis variables, `proc report` summarises them by default
This behaviour is different from simply listing row-level data
To help verify the result, we compare it with a `proc summary` step that calculates sums
This distinction between display variables and analysis variables is important in PROC REPORT
proc report data=class nowindows out=report_numeric_sum; columns age height weight; run; proc summary data=class; var age height weight; output out=stats01 sum=/autoname; run;
Copy Code
View Log
SAS Log
proc report data=class nowindows out=report_numeric_sum; columns age height weight; run; NOTE: There were 19 observations read from the data set WORK.CLASS. NOTE: The data set WORK.REPORT_NUMERIC_SUM has 1 observations and 4 variables. NOTE: PROCEDURE REPORT used (Total process time): real time 0.01 seconds cpu time 0.01 seconds proc summary data=class; var age height weight; output out=stats01 sum=/autoname; run; NOTE: There were 19 observations read from the data set WORK.CLASS. NOTE: The data set WORK.STATS01 has 1 observations and 5 variables. NOTE: PROCEDURE SUMMARY used (Total process time): real time 0.00 seconds cpu time 0.00 seconds
`report_numeric_sum` contains the default summarised values produced by `proc report` for the numeric columns
`stats01` provides a reference summary generated by another procedure
Compare the two outputs and confirm that the report is showing summary-style results rather than student-level rows
View Data
Dataset View
Display numeric variables without summarising
To force detail rows, we use `define` statements and set each variable as `display`
This tells `proc report` to treat the numeric columns as ordinary displayed variables instead of analysis variables
The output will now show one row per observation
proc report data=class nowindows out=report_numeric_detail; columns age height weight; define age / display; define height / display; define weight / display; run;
Copy Code
View Log
SAS Log
proc report data=class nowindows out=report_numeric_detail; columns age height weight; define age / display; define height / display; define weight / display; run; NOTE: There were 19 observations read from the data set WORK.CLASS. NOTE: The data set WORK.REPORT_NUMERIC_DETAIL has 19 observations and 4 variables. NOTE: PROCEDURE REPORT used (Total process time): real time 0.01 seconds cpu time 0.01 seconds
`report_numeric_detail` now holds row-level values for each observation
Compare this dataset with `report_numeric_sum` to understand the effect of the `define ... / display` statements
View Data
Dataset View
Add grouping to a report
Grouping is one of the main strengths of PROC REPORT
When a variable is defined as `group`, PROC REPORT organises detail rows by that variable and suppresses repeated display of the same group value
This produces a cleaner report for grouped listings
proc report data=class nowindows out=report_grouped; columns sex name age height; define sex / group; define name / display; define age / display; define height / display; run;
Copy Code
View Log
SAS Log
proc report data=class nowindows out=report_grouped; columns sex name age height; define sex / group; define name / display; define age / display; define height / display; run; NOTE: Groups are not created because the usage of NAME is DISPLAY. To avoid this note, change all GROUP variables to ORDER variables. NOTE: There were 19 observations read from the data set WORK.CLASS. NOTE: The data set WORK.REPORT_GROUPED has 19 observations and 5 variables. NOTE: PROCEDURE REPORT used (Total process time): real time 0.03 seconds cpu time 0.00 seconds
Review the report and observe how rows are grouped by `sex`
The output dataset helps you compare grouped report structure with the original input data
View Data
Dataset View
Key points to remember
`proc report` creates flexible tabular reports from SAS data
The `columns` statement controls the variables and order of display
Numeric variables may be summarised by default when used as analysis items
`define variable / display;` forces detail display instead of summary analysis behaviour
`define variable / group;` organises output by group values