PROC PRINT is the simplest way to display the contents of a SAS dataset as a formatted table in the output window
By default, it prints every variable and every observation, with an automatically generated observation number column on the left
Despite its simplicity, PROC PRINT has several useful options for controlling which variables to show, filtering rows, grouping output, adding totals, and applying labels
It is widely used for quick data inspection during development and for simple formatted listings in reports
Create sample data
The dataset `students` contains demographic and score information for a small group of students across two classes
It will be used throughout this lesson to demonstrate PROC PRINT options progressively
SAS Log
The `label` statement assigns descriptive labels to each variable — these will be used in later examples when `label` is requested in PROC PRINT
Inspect the dataset and confirm eight rows with the five variables before proceeding
Dataset View
Basic PROC PRINT - print all variables and observations
The minimal PROC PRINT statement requires only the `data=` option
By default, SAS adds an `Obs` column on the left showing the row number, prints every variable, and shows every observation
SAS Log
The output shows all eight rows and all five variables with the auto-generated `Obs` column
The column headings show variable names, not labels, because the `label` option has not been requested yet
NOOBS - suppress the observation number column
The `noobs` option removes the automatic `Obs` column from the output
This is useful when the row number adds no meaning to the output or when you want cleaner report-style output
SAS Log
Compare with the previous output — the `Obs` column is gone and the table starts directly with the first data variable
VAR - select which variables to print
The `var` statement lists the variables to include in the output, in the order they should appear
Variables not listed are excluded from the printed output even though they remain in the dataset
This is useful when a dataset has many columns but only a few are relevant for a particular listing
SAS Log
Only `name`, `age`, and `score` appear — `class` and `sex` are excluded from this print
The variable order in the output matches the order listed in the `var` statement, not the order in the dataset
WHERE - filter which observations to print
The `where` statement applies a filter before printing — only rows satisfying the condition are shown
This is equivalent to subsetting in a DATA step but does not create a new dataset — it only affects what is printed
SAS Log
Only students with a score of 85 or higher should appear — confirm that Brian (76), David (81), Frank (70), and Henry (78) are excluded
Four students (Alice 88, Carol 92, Emma 95, Grace 89) should remain
LABEL - display variable labels instead of names
The `label` option tells PROC PRINT to use the variable labels as column headings instead of the variable names
Labels were defined in the dataset using the `label` statement when the data was created
This makes output much more readable for end users who may not know the technical variable names
SAS Log
The column headings now show descriptive text such as `Student Name`, `Class Group`, and `Test Score` instead of the short variable names
The underlying variable names are unchanged — only the display heading is affected
BY - group output by a variable
The `by` statement groups the printed output by the values of the specified variable
The data must be sorted by the BY variable before running PROC PRINT, just as with a DATA step BY statement
A separator line and the BY variable value are printed before each group, making the grouping visible in the output
SAS Log
The output is split into two sections — one for Class A and one for Class B — with a header line showing the group value above each section
Confirm that the four Class A students and four Class B students are in the correct groups
SUM - add column totals
The `sum` statement lists numeric variables for which a grand total should be printed at the bottom of the output
When used with a `by` statement, subtotals are also printed at the end of each group
This is a fast way to add totals to a listing without creating a separate summary dataset
SAS Log
A subtotal row for `score` appears at the bottom of each class group, and a grand total row appears at the very end of the output
Manually add the scores for each class and verify that the subtotals are correct: Class A should be 88+76+95+89=348, Class B should be 92+81+70+78=321
OBS= - limit the number of rows printed
The `obs=` dataset option limits how many rows are read from the input dataset
This is useful during development when you want to quickly check the layout or format of a report without printing the full dataset
SAS Log
Only the first three rows of `students` are printed — useful as a quick check of column headings and formats before running against a full dataset
Key points to remember
`proc print data=dsn;` prints all variables and observations with an auto Obs column
`noobs` removes the Obs column for cleaner report output
`var` selects and orders the columns to display
`where` filters rows without modifying the source dataset
`label` uses variable labels as column headings instead of variable names
`by` groups output — the data must be pre-sorted by the BY variable
`sum` adds subtotals and grand totals for listed numeric variables
`obs=` on the dataset option limits how many rows are read — useful for development