6.1 - Basic Reports

6.1 - Basic Reports

As you are already well aware, the PRINT procedure is the mechanism by which we can print and therefore see the contents — variables and observations — of a SAS data set. Using the PRINT procedure, we can create quite informative list reports. The PRINT procedure takes the following general form:

PROC PRINT options;
	statement1;
	statement2;
	etc;
RUN;

As usual, throughout this lesson, we'll look at some examples in order to learn about the various options and features of the PRINT procedure.

Example 6.1

The following SAS code merely creates a baseline data set called basic that we can print throughout the lesson:

OPTIONS LS = 75 PS = 58 NODATE;

DATA basic;
  input subj 1-4 name $ 6-23 clinic $ 25-28
        gender 30 no_vis 32-33 type_vis 35-37
        expense 39-45;
  DATALINES;
1024 Alice Smith        LEWN 1  7 101 1001.98
1167 Maryann White      LEWN 1  2 101 2999.34
1168 Thomas Jones       ALTO 2 10 190 3904.89
1201 Benedictine Arnold ALTO 2  1 190 1450.23
1302 Felicia Ho         MNMC 1  7 190 1209.94
1471 John Smith         MNMC 2  6 187 1763.09
1980 Jane Smiley        MNMC 1  5 190 3567.00
  ;
RUN;

PROC PRINT data = basic;
RUN;
Obs subj name clinic gender no_vis type_vis expense
1 1024 Alice Smith LEWN 1 7 101 1001.98
2 1167 Maryann White LEWN 1 2 101 2999.34
3 1168 Thomas Jones ALTO 2 10 190 3904.89
4 1201 Benedict Arnold ALTO 2 1 190 1450.23
5 1302 Felicia Ho MNMC 1 7 190 1209.94
6 1471 John Smith MNMC 2 6 187 1763.09
7 1980 Jane Smiley MNMC 1 5 190 3567.00

For the sake of context, define the variables in the data set as follows:

  • subj: as usual, subject id number
  • name: patient's name
  • clinic: where patient was treated
  • gender: gender of subject (1: female, 2: male)
  • no_vis: number of visits to a medical facility (0, 1, 2,...)
  • type_vis: type of visit (101: gynecology, 190: physical therapy 187: cardiology)
  • expense: medical charges in dollars.

The PRINT procedure that tells SAS to print the basic data set is the simplest form of the PRINT procedure and one that we have, of course, already used numerous times throughout the semester. Launch and run the SAS code so that the data set becomes available for use throughout the lesson. You should also review the resulting report to familarize yourself with its basic characteristics. You should see that by default:

  1. All observations and variables in the data set are printed
  2. A column for observation numbers appears on the far left
  3. Variables appear in the order in which they occur in the data set

Example 6.2

By default, the PRINT procedure lists all of the variables contained in a SAS data set. We can use the PRINT procedure's VAR statement to not only select variables, but also to control the order in which the variables appear in our reports. The following SAS program uses the VAR statement to tell SAS to print just a subset of the variables — name, no_vis and expense — contained in the basic data set:

PROC PRINT data = basic;
   var name no_vis expense;
RUN;
Obs name no_vis expense
1 Alice Smith 7 1001.98
2 Maryann White 2 2999.34
3 Thomas Jones 10 3904.89
4 Benedict Arnold 1 1450.23
5 Felicia Ho 7 1209.94
6 John Smith 6 1763.09
7 Jane Smiley 5 3567.00

In general, the VAR statement tells SAS to print the variables in the order specified in the VAR statement. Launch and run the SAS program, and review the output to convince yourself that SAS indeed printed just the three variables — name, no_vis and expense — in that order.

Example 6.3

Using the NOOBS option, we can suppress the printing of the default observation number. The following SAS program illustrates the PRINT procedure's NOOBS option:

PROC PRINT data = basic noobs;
   var name no_vis expense;
RUN;
name no_vis expense
Alice Smith 7 1001.98
Maryann White 2 2999.34
Thomas Jones 10 3904.89
Benedict Arnold 1 1450.23
Felicia Ho 7 1209.94
John Smith 6 1763.09
Jane Smiley 5 3567.00

Launch and run the SAS program, and review the resulting report to convince yourself that the observation number has been suppressed.


Legend
[1]Link
Has Tooltip/Popover
 Toggleable Visibility