Table of Contents
PROC PRINT is a SAS procedure that allows users to display data in a tabular format. It provides a quick and efficient way to visually inspect and verify data, as well as to create reports for further analysis. By specifying variables and options, users can customize the output of PROC PRINT to meet their specific needs. This procedure is commonly used in data exploration, data cleaning, and quality assurance processes. It can also be integrated with other SAS procedures and functions for more advanced data manipulation and reporting. Overall, PROC PRINT is a valuable tool for organizing and presenting data in a clear and concise manner in SAS.
Use PROC PRINT in SAS (With Examples)
You can use PROC PRINT in SAS to print the rows in a dataset.
Here are some common ways to use PROC PRINT in practice:
Method 1: Print Entire Dataset
/*print entire dataset*/
proc printdata=my_data;
Method 2: Print First N Observations in Dataset
/*print only first five rows*/
proc printdata=my_data(obs=5);Method 3: Print Specific Variables in Dataset
/*print rows for team and points variables only*/
proc printdata=my_data;
var team points;
run;Method 4: Print Dataset Grouped by Specific Variable
/*sort rows of dataset by values in team column*/ proc sortdata=my_data;
by team;
run;
/*print entire dataset grouped by values in team column*/
proc printdata=my_data;
by team;
run;Method 5: Print Dataset with Title and Footer
/*print dataset with title and footer*/ proc sortdata=my_data;
title "First Five Rows of Basketball Dataset";
footnote "2015 Data Source";
run;The following examples show how to use each method in practice with the following dataset in SAS that contains information about various basketball players:
/*create dataset*/
data my_data;
input team $ position $ points assists;
datalines;
A Guard 14 4
A Guard 22 6
A Guard 24 9
A Forward 13 8
A Forward 13 9
A Guard 10 5
B Guard 24 4
B Guard 22 6
B Forward 34 2
B Forward 15 5
B Forward 23 5
B Guard 10 4
;
run;Example 1: Print Entire Dataset
We can use PROC PRINT with the following syntax to print every row in the dataset:
/*print entire dataset*/
proc printdata=my_data;
Notice that every row in the dataset has been printed.
Example 2: Print First N Observations in Dataset
We can use PROC PRINT with the OBS statement to only print the first five observations from the dataset:
/*print first five rows of dataset*/
proc printdata=my_data(obs=5);
Notice that only the first five rows in the dataset are printed.
Example 3: Print Specific Variables in Dataset
We can use PROC PRINT with the VAR statement to only print the team and points variables from the dataset:
/*print rows for team and points variables only*/
proc printdata=my_data(obs=5);
var team points;
run;
Notice that only the team and points variables from the dataset are printed.
Example 4: Print Dataset Grouped by Specific Variable
We can use PROC PRINT with the BY statement to print the dataset grouped by unique values for the team variable:
/*sort rows of dataset by values in team column*/ proc sortdata=my_data;
by team;
run;
/*print entire dataset grouped by values in team column*/
proc printdata=my_data;
by team;
run;
Notice that the first table in the output shows the rows for team A and the second table shows the rows for team B.
Example 5: Print Dataset with Title and Footer
We can use PROC PRINT with the TITLE and FOOTER statements to print the dataset with a title and a footer:
/*print dataset with title and footer*/ proc sortdata=my_data;
title "First Five Rows of Basketball Dataset";
footnote "2015 Data Source";
run;
Notice that a title is shown above the dataset and a footer is shown below it.
The following tutorials explain how to perform other common tasks in SAS:
Cite this article
stats writer (2024). How can I use PROC PRINT in SAS?. PSYCHOLOGICAL SCALES. Retrieved from https://scales.arabpsychology.com/stats/how-can-i-use-proc-print-in-sas/
stats writer. "How can I use PROC PRINT in SAS?." PSYCHOLOGICAL SCALES, 23 Jun. 2024, https://scales.arabpsychology.com/stats/how-can-i-use-proc-print-in-sas/.
stats writer. "How can I use PROC PRINT in SAS?." PSYCHOLOGICAL SCALES, 2024. https://scales.arabpsychology.com/stats/how-can-i-use-proc-print-in-sas/.
stats writer (2024) 'How can I use PROC PRINT in SAS?', PSYCHOLOGICAL SCALES. Available at: https://scales.arabpsychology.com/stats/how-can-i-use-proc-print-in-sas/.
[1] stats writer, "How can I use PROC PRINT in SAS?," PSYCHOLOGICAL SCALES, vol. X, no. Y, ص Z-Z, June, 2024.
stats writer. How can I use PROC PRINT in SAS?. PSYCHOLOGICAL SCALES. 2024;vol(issue):pages.
