🔍 What is PROC PRINT in SAS?
PROC PRINT
is a SAS procedure that prints the observations in a SAS dataset to the output window. It provides a tabular view of your data and is commonly used for checking data during the data cleaning and analysis phase.
🧱 Basic Syntax of PROC PRINT
Explanation:
PROC PRINT
tells SAS to initiate the print procedure.DATA=dataset-name
specifies the dataset to print.RUN;
executes the procedure.
📝 Example: Basic PROC PRINT
This code will output all rows and columns of the employees
dataset.
🎯 Using PROC PRINT with SELECTED VARIABLES
You can use the VAR
statement to print only specific columns from your dataset.
This will display only the Name
and Department
columns.
🔢 Adding Row Numbers with ID Statement
The ID
statement lets you replace the default observation number with a variable value.
Now, instead of row numbers (1, 2, 3), SAS will display the values from the ID
column.
🧾 Using Labels in Output
To display more meaningful column headers, you can use labels.
Now the column header will display as Annual Salary.
🎯 Filtering Rows with WHERE Statement
The WHERE
clause lets you filter records before printing.
This will display only the rows where the department is IT.
📌 More Useful Options
- OBS=number: Limits number of observations printed.
- NOOBS: Suppresses the default row number column.
- LABEL: Displays labels instead of variable names.
- TITLE: Adds a title to the output.
💡 Best Practices for PROC PRINT
- Use
VAR
andID
to improve readability. - Always apply
WHERE
clauses for large datasets. - Use
LABEL
for user-friendly column headings in reports.
➕Here are some More Examples for Proc print -
1. First Proc print to get the output for sasuser.admit dataset in output window
Code -
proc print data=sasuser.admit;run;
proc print data=sasuser.admit;sum fee;run;
3. To get the sum total for more than one specified columns
proc print data=sasuser.admit;sum fee height;run;
4. Selecting variables for printing, the use of the var keyword
proc print data=sasuser.admit;var age sex height fee;sum fee ;run;
5. Selecting variables for printing without default obs column
proc print data=sasuser.admit noobs;var age sex height fee;sum fee ;run;
6. Use of no obs - It gives the total no of observations and shows the obs column too
Code -
proc print data=sasuser.admit no obs;var age sex height fee;sum fee ;run;/* same can be achieved by N;proc print data=sasuser.admit N;var age sex height fee;sum fee ;run;
7. Use of ID statement - The id statement basically replaces the obs column with the specified variable against the id keyword
proc print data=admit;var age sex height fee;id name;sum fee ;run;
8. More than one variable in ID statement - If you specify two variables in the id statement then those two vars replace the obs columns and proc print of data is also displayed.
proc print data=sasuser.admit;id name age height;run;
9. The use of where statement is to filter the observations (Note - we can’t use IF statement in proc print to filter data)
proc print data=admit;var age sex height fee;where age gt 30;sum fee ;run;
10. The use of '?' operator along with where condition for filtering the data
proc print data=sasuser.admit;var age sex height fee name;where name ? 'er';sum fee ;run;
11. The use of double spacing in the listing output between the rows
proc print data=sasuser.admit double;var age sex height fee name;where name ? 'er';sum fee ;run;
12. Titles in Proc print - The use of title in the listing output, title or title1 is the same
title1 'Proc Print Examples';title3 'Please subscribe datahark on Facebook, youtube and visit our website';title4 'website - https://www.datahark.in/'title5 'facebook - https://www.facebook.com/datahark/'title6 'youtube - https://www.youtube.com/channel/UCZAPTZ0YvrTiKdh2WgnxEBA or Search for Datahark'proc print data=sasuser.admit;var age sex height fee name;where name ? 'er';sum fee ;run;
📌 Conclusion
PROC PRINT
is a foundational tool in the SAS programmer’s toolkit. Whether you’re debugging a data step, presenting a report, or just exploring your data, it offers a quick and flexible way to visualize your dataset.
Mastering PROC PRINT
will make your data review and reporting tasks much easier. Try the examples above with your own datasets and see the results instantly!
0 Comments
If you have any doubt please comment or write us to - datahark12@gmail.com