How to Use PROC PRINT in SAS (With Examples)

Proc print is a procedure in SAS used to display the observations and variables of a SAS data set in a tabular format. It can be used to view the contents of a data set, as well as to customize the output with options such as changing the column size, suppressing output, and defining a break. To use Proc print, the user needs to specify the dataset, the variables, and any desired options. It can also be used to create a summary report containing counts, sums, and other statistics.


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 print data=my_data;

Method 2: Print First N Observations in Dataset

/*print only first five rows*/ 
proc print data=my_data(obs=5);

Method 3: Print Specific Variables in Dataset

/*print rows for team and points variables only*/ 
proc print data=my_data;
    var team points;
run;

Method 4: Print Dataset Grouped by Specific Variable

/*sort rows of dataset by values in team column*/ 
proc sort data=my_data;
    by team;
run;

/*print entire dataset grouped by values in team column*/
proc print data=my_data;
    by team;
run;

Method 5: Print Dataset with Title and Footer

/*print dataset with title and footer*/ 
proc sort data=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 print data=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 print data=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 print data=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 sort data=my_data;
    by team;
run;

/*print entire dataset grouped by values in team column*/
proc print data=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 sort data=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:

x