You can use proc report in SAS to generate a report for a dataset in SAS with the exact formatting that you’d like.
This procedure uses the following basic syntax:
/*create report*/
proc report data=my_data;
run;
This will generate a report that displays the rows in a dataset exactly as they appear.
However, you can customize the output of the report in a variety of ways.
For example, we can use the following syntax to create a more customized report:
/*create customized report*/
title 'Player Statistics for Dallas Mavericks';
proc report data=my_data;
where team='Mavs';
column conf team points;
define conf / display 'Conference' center;
run;
Here’s what each statement does:
- title creates a title for the report
- where filters the dataset to only contain rows where team is ‘Mavs’
- column specifies which columns to display in the report in a certain order
- display specifies the title to use for the column called conf and center specifies the text to be centered in the column
The following example shows how to use proc report in practice.
Note: Refer to the online documentation for a complete explanation of all the ways you can customize a report.
Example: Using Proc Report in SAS
Suppose we have the following dataset in SAS that contains information about various basketball players:
/*create dataset*/
data my_data;
input team $ points rebounds conf $;
datalines;
Celtics 12 5 East
Celtics 14 7 East
Celtics 15 8 East
Celtics 18 13 East
Mavs 31 12 West
Mavs 32 6 West
Mavs 35 4 West
Mavs 36 10 West
Mavs 40 12 West
;
run;
/*view dataset*/
proc print data=my_data;
We can use proc report in the following manner to print the entire dataset as it appears:
/*create report that displays entire dataset*/
proc report data=my_data;
run;
The report simply contains the entire dataset.
However, we can use proc report to generate a customized report by using the following syntax:
/*create customized report*/
title 'Player Statistics for Dallas Mavericks';
proc report data=my_data;
where team='Mavs';
column conf team points;
define conf / display 'Conference' center;
run;
Notice that this report contains the following differences compared to the original report:
- This report has a title
- This report only contains rows where team is ‘Mavs’
- This report only contains the conf, team, and points columns
- This report uses ‘Conference’ as the title for conf and center-aligns the values in the conf column
This is just a simple example of how to create a customized report using proc report in SAS.
Feel free to explore the online documentation to see how you can further customize the output and generate a report that appears exactly how you’d like in SAS.
Additional Resources
The following tutorials explain how to perform other common tasks in SAS:
How to Use Proc Append in SAS
How to Use Proc Tabulate in SAS
How to Use Proc Summary in SAS