Share it!

In the realm of data analysis and programming, presenting your data clearly and effectively is crucial. The PROC PRINT procedure in SAS is a fundamental tool that enables SAS professionals to display and examine datasets. This article serves as a comprehensive guide for beginners and seasoned users alike, detailing how to use PROC PRINT effectively to display your data in SAS.

Understanding PROC PRINT

What is PROC PRINT?

PROC PRINT is a SAS procedure used to display the contents of a dataset. It provides a quick and efficient way to view data, helping users to verify and inspect datasets after data manipulation or before further analysis. This procedure outputs the data in a tabular format, making it easy to identify trends, patterns, and discrepancies.

Basic Syntax of PROC PRINT

The basic syntax for using PROC PRINT is as follows:

SAS
PROC PRINT DATA=dataset_name;
RUN;
  • DATA=dataset_name: Specifies the dataset you want to display.

Getting Started with PROC PRINT

Example Dataset

Let’s begin by creating a simple dataset for demonstration purposes. We will create a dataset named employees containing employee data, including their names, ages, and salaries.

SAS
DATA employees;
    INPUT Name $ Age Salary;
    DATALINES;
Alice 30 70000
Bob 25 55000
Charlie 35 90000
Diana 28 62000
Edward 40 85000
;
RUN;

Displaying the Dataset with PROC PRINT

Now that we have our dataset, we can use PROC PRINT to display its contents:

SAS
PROC PRINT DATA=employees;
RUN;

This code will output the following table, displaying the employees dataset:

NameAgeSalary
Alice3070000
Bob2555000
Charlie3590000
Diana2862000
Edward4085000

Customizing Your Output

While the default output from PROC PRINT is useful, SAS provides several options to customize your display.

Selecting Variables to Display

You can specify which variables to display using the VAR statement. For example, if you want to display only the Name and Salary variables, you can do the following:

SAS
PROC PRINT DATA=employees;
    VAR Name Salary;
RUN;

Adding a Title

Adding titles to your output can make it more informative and easier to understand. Use the TITLE statement before the PROC PRINT statement to add a title:

SAS
TITLE "Employee Salary Information";
PROC PRINT DATA=employees;
RUN;

Adding Conditional Formatting

You can use the WHERE statement to filter the data displayed based on specific conditions. For example, to display only employees with a salary greater than $60,000, you can write:

SAS
PROC PRINT DATA=employees;
    WHERE Salary > 60000;
RUN;

Advanced Options in PROC PRINT

Modifying Column Headers

If you want to change the column headers in your output, you can use the LABEL statement to define custom labels for your variables. For instance, you can change “Name” to “Employee Name” and “Salary” to “Annual Salary”:

SAS
DATA employees;
    INPUT Name $ Age Salary;
    LABEL Name = "Employee Name"
          Salary = "Annual Salary";
    DATALINES;
Alice 30 70000
Bob 25 55000
Charlie 35 90000
Diana 28 62000
Edward 40 85000
;
RUN;

PROC PRINT DATA=employees;
RUN;

Controlling the Output

You can control the number of rows printed using the OBS= option, allowing you to limit the output to a specified number of observations:

SAS
PROC PRINT DATA=employees (OBS=3);
RUN;

Using the NOOBS Option

The NOOBS option can be used to suppress the display of observation numbers in your output. This can make your table cleaner if you don’t need the observation numbers:

SAS
PROC PRINT DATA=employees NOOBS;
RUN;

Exporting PROC PRINT Output

Exporting to RTF or HTML

You can also export the output of PROC PRINT to different formats, such as RTF (Rich Text Format) or HTML. This can be accomplished using the ODS statement. For example, to export the output to an RTF file, you can use:

SAS
ODS RTF FILE='employees_report.rtf';

PROC PRINT DATA=employees;
RUN;

ODS RTF CLOSE;

This code generates a report in RTF format that can be opened in word processing applications.

Practical Applications of PROC PRINT

  1. Data Verification: Use PROC PRINT to verify the contents of your datasets after import or data manipulation.
  2. Quick Data Insights: Display subsets of data for quick insights during exploratory data analysis (EDA).
  3. Reporting: Generate reports to present findings to stakeholders, complete with titles and custom labels for clarity.
  4. Data Quality Checks: Use conditional statements to identify anomalies in the data, ensuring data quality.

FAQs About PROC PRINT

  1. What is PROC PRINT used for?
  • PROC PRINT is used to display the contents of a dataset in a tabular format.
  1. How do I display specific variables using PROC PRINT?
  • Use the VAR statement to specify which variables to display in the output.
  1. Can I add titles to my PROC PRINT output?
  • Yes, you can use the TITLE statement before PROC PRINT to add informative titles.
  1. How can I filter my data in PROC PRINT?
  • Use the WHERE statement to filter the data based on specific conditions.
  1. Is it possible to suppress observation numbers in the output?
  • Yes, you can use the NOOBS option to suppress the display of observation numbers.
  1. Can I customize column headers in PROC PRINT?
  • Yes, you can use the LABEL statement to define custom labels for your variables.
  1. How do I limit the number of rows displayed?
  • Use the OBS= option to limit the output to a specified number of observations.
  1. Can I export PROC PRINT output to formats like RTF or HTML?
  • Yes, you can use the ODS statement to export PROC PRINT output to various formats, including RTF and HTML.
  1. What types of analyses can I perform using PROC PRINT?
  • PROC PRINT is primarily for displaying data; however, it can assist in exploratory data analysis (EDA) by providing quick insights into datasets.
  1. Where can I find more information about PROC PRINT?
    • The official SAS Documentation provides comprehensive details and examples of PROC PRINT.

External Resources for Further Learning

Conclusion

PROC PRINT is an indispensable tool for SAS professionals, providing a straightforward way to display and examine datasets. By mastering PROC PRINT, you can enhance your data presentation capabilities, making your analyses more transparent and effective. Whether you’re conducting exploratory data analysis, verifying datasets, or generating reports, PROC PRINT is a powerful ally in your SAS programming toolkit. Happy coding!


Share it!