Saturday, November 28, 2020

PROC PRINT in SAS - What Does the PRINT Procedure Do

πŸ” 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

PROC PRINT DATA=dataset-name;
RUN;

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

DATA employees;
INPUT ID Name $ Department $ Salary; DATALINES; 1 John HR 50000 2 Alice IT 70000 3 Bob Finance 60000 ; RUN; PROC PRINT DATA=employees; RUN;

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.

PROC PRINT DATA=employees;
VAR Name Department; RUN;

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.

PROC PRINT DATA=employees;
ID ID; VAR Name Department Salary; RUN;

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.

DATA employees;
SET employees; LABEL Salary = 'Annual Salary'; RUN; PROC PRINT DATA=employees LABEL; VAR Name Salary; RUN;

Now the column header will display as Annual Salary.


🎯 Filtering Rows with WHERE Statement

The WHERE clause lets you filter records before printing.

PROC PRINT DATA=employees;
WHERE Department = 'IT'; RUN;

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.

PROC PRINT DATA=employees (OBS=2) NOOBS LABEL;
TITLE "Employee Report"; RUN;

πŸ’‘ Best Practices for PROC PRINT

  • Use VAR and ID 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;
Click here to Read more Β»

Labels: , , , ,