Chapter 4. Creating List Reports

Overview

Introduction

To list the information in a data set, you can create a report with a PROC PRINT step. Then you can enhance the report with additional statements and options to create reports like those shown below.

Introduction

Objectives

In this chapter, you learn to

  • specify SAS data sets to print

  • select variables and observations to print

  • sort data by the values of one or more variables

  • specify column totals for numeric variables

  • double space SAS listing output

  • add titles and footnotes to procedure output

  • assign descriptive labels to variables

  • apply formats to the values of variables.

Creating a Basic Report

To produce a simple list report, you first reference the library in which your SAS data set is stored. If you want, you can also set system options to control the appearance of your reports. Then you submit a basic PROC PRINT step.

In the program below, the PROC PRINT statement invokes the PRINT procedure and specifies the data set Therapy in the SAS data library to which the libref Patients has been assigned.

libname patients 'c:
ecordspatients';
proc print data=patients.therapy;
run;

Notice the layout of the resulting report. By default,

  • all observations and variables in the data set are printed

  • a column for observation numbers appears on the far left

  • variables appear in the order in which they occur in the data set.

Creating a Basic Report
Creating a Basic Report
Creating a Basic Report

Selecting Variables

By default, a PROC PRINT step lists all the variables in a data set. You can select variables and control the order in which they appear by using a VAR statement in your PROC PRINT step.

For example, the following VAR statement specifies that only the variables Age, Height, Weight, and Fee be printed, in that order:

proc print data=clinic.admit;
   var age height weight fee;
run;

The procedure output from the PROC PRINT step with the VAR statement lists only the values for the variables Age, Height, Weight, and Fee.

Selecting Variables

In addition to selecting variables, you can control the default Obs column that PROC PRINT displays to list observation numbers. If you prefer, you can choose not to display observation numbers.

Selecting Variables

Removing the OBS Column

To remove the Obs column, specify the NOOBS option in the PROC PRINT statement.

proc print data=work.example noobs;
   var age height weight fee;
run;
Removing the OBS Column

Identifying Observations

You've learned how to remove the Obs column altogether. As another alternative, you can use one or more variables to replace the Obs column in the output.

To specify which variables should replace the Obs column, use the ID statement. This technique is particularly useful when observations are too long to print on one line.

Example

To replace the Obs column and identify observations based on an employee's ID number and last name, you can submit the following program.

proc print data=sales.reps;
    id idnum lastname;
run;

This is HTML output from the program:

Example
Example
Example

If a variable in the ID statement also appears in the VAR statement, the output contains two columns for that variable. In the example below, the variable IDnum appears twice.

proc print data=sales.reps;
    id idnum lastname;
    var idnum sex jobcode salary;
run;
Example

Selecting Observations

By default, a PROC PRINT step lists all the observations in a data set. You can control which observations are printed by adding a WHERE statement to your PROC PRINT step. There can only be one WHERE statement in a step.

For example, the following WHERE statement selects only observations for which the value of Age is greater than 30:

proc print data=clinic.admit;
   var age height weight fee;
   where age>30;
run;

Here is the procedure output from the PROC PRINT step with the WHERE statement:

Selecting Observations

Specifying WHERE Expressions

In the WHERE statement you can specify any variable in the SAS data set, not just the variables that are specified in the VAR statement. The WHERE statement works for both character and numeric variables. To specify a condition based on the value of a character variable, you must

  • enclose the value in quotation marks

  • write the value with lower and uppercase letters exactly as it appears in the data set.

You use the following comparison operators to express a condition in the WHERE statement:

Symbol

Meaning

Example

= or eq

equal to

where name='Jones, C.';

^= or ne

not equal to

where temp ne 212;

> or gt

greater than

 

< or lt

less than

where partno lt "BG05";

>= or ge

greater than or equal to

where id>='1543';

<= or le

less than or equal to

where pulse le 85;
Specifying WHERE Expressions

Using the CONTAINS Operator

The CONTAINS operator selects observations that include the specified substring. The mnemonic equivalent for the CONTAINS operator is ?. You can use either the CONTAINS keyword or the mnemonic equivalent in your code, as shown below.

where firstname CONTAINS 'Jon';
where firstname ? 'Jon';

Specifying Compound WHERE Expressions

You can also use WHERE statements to select observations that meet multiple conditions. To link a sequence of expressions into compound expressions, you use logical operators, including the following:

Operator

 

Meaning

AND

&

and, both. If both expressions are true, then the compound expression is true.

OR

|

or, either. If either expression is true, then the compound expression is true.

Examples of WHERE Statements

  • You can use compound expressions like these in your WHERE statements:

    where age<=55 and pulse>75;
    where area='A' or region='S';
    where ID>1050 and state='NC';
  • When you test for multiple values of the same variable, you specify the variable name in each expression:

    where actlevel='LOW' or actlevel='MOD';
    where fee=124.80 or fee=178.20;
  • You can use the IN operator as a convenient alternative:

    where actlevel in ('LOW','MOD');
    where fee in (124.80,178.20);
  • To control the way compound expressions are evaluated, you can use parentheses (expressions in parentheses are evaluated first):

    where (age<=55 and pulse>75) or area='A';
    where age<=55 and (pulse>75 or area='A');

Sorting Data

By default, PROC PRINT lists observations in the order in which they appear in your data set. To sort your report based on values of a variable, you must use PROC SORT to sort your data before using the PRINT procedure to create reports from the data.

The SORT procedure

  • rearranges the observations in a SAS data set

  • creates a new SAS data set that contains the rearranged observations

  • replaces the original SAS data set by default

  • can sort on multiple variables

  • can sort in ascending or descending order

  • does not generate printed output

  • treats missing values as the smallest possible values.

Example

In the following program, the PROC SORT step sorts the permanent SAS data set Clinic.Admit by the values of the variable Age within the values of the variable Weight and creates the temporary SAS data set Wgtadmit. Then the PROC PRINT step prints the Wgtadmit data set.

proc sort data=clinic.admit out=work.wgtadmit; 
   by weight age;
run;
proc print data=work.wgtadmit;
   var age height weight fee;
   where age>30;
run;

The report displays observations in ascending order of age within weight.

Example

Adding the DESCENDING option to the BY statement sorts observations in ascending order of age within descending order of weight. Notice that DESCENDING applies only to the variable Weight.

proc sort data=clinic.admit out=work.wgtadmit;
   by descending weight age;
run;
proc print data=work.wgtadmit;
   var age height weight fee;
   where age>30;
run;
Example

Generating Column Totals

To produce column totals for numeric variables, you can list the variables to be summed in a SUM statement in your PROC PRINT step.

The SUM statement in the following PROC PRINT step requests column totals for the variable BalanceDue:

proc print data=clinic.insure;
	var name policy balancedue;
	where pctinsured < 100;
	sum balancedue;
run;

Column totals appear at the end of the report in the same format as the values of the variables.

Generating Column Totals

Requesting Subtotals

You might also want to subtotal numeric variables. To produce subtotals, add both a SUM statement and a BY statement to your PROC PRINT step.

Example

The SUM statement in the following PROC PRINT step requests column totals for the variable Fee, and the BY statement produces a subtotal for each value of ActLevel.

proc sort data=clinic.admit out=work.activity;
   by actlevel;
run;
proc print data=work.activity;
   var age height weight fee;
   where age>30;
   sum fee; 
   by actlevel;
run;

In the output, the BY variable name and value appear before each BY group. The BY variable name and the subtotal appear at the end of each BY group.

Example

Creating a Customized Layout with BY Groups and ID Variables

In the previous example, you may have noticed the redundant information for the BY variable. For example, in the partial PROC PRINT output below, the BY variable ActLevel is identified both before the BY group and for the subtotal.

Creating a Customized Layout with BY Groups and ID Variables

To show the BY variable heading only once, you can use an ID statement and a BY statement together with the SUM statement. When an ID statement specifies the same variable as the BY statement,

  • the Obs column is suppressed

  • the ID/BY variable is printed in the left-most column

  • each ID/BY value is printed only at the start of each BY group and on the line that contains that group's subtotal.

Example

The ID, BY, and SUM statements work together to produce the output shown below. The ID variable is listed only once for each BY group and once for each sum. The BY lines are suppressed. Instead, the value of the ID variable, ActLevel, identifies each BY group.

proc sort data=clinic.admit out=work.activity;
   by actlevel;
run;
proc print data=work.activity;
   var age height weight fee;
   where age>30;
   sum fee; 
   by actlevel; 
   id actlevel;
run;
Example

Requesting Subtotals on Separate Pages

As another enhancement to your PROC PRINT report, you can request that each BY group be printed on a separate page by using the PAGEBY statement.

Example

The PAGEBY statement in the program below prints BY groups for the variable ActLevel separately. The BY groups appear on separate pages in the output.

proc sort data=clinic.admit out=work.activity;
   by actlevel;
run;
proc print data=work.activity;
   var age height weight fee;
   where age>30;
   sum fee; 
   by actlevel; 
   id actlevel; 
   pageby actlevel;
run;
Example

Double Spacing Listing Output

If you are generating SAS listing output, one way to control the layout is to double space it. To do so, specify the DOUBLE option in the PROC PRINT statement. For example,

proc print data=clinic.stress double;
	var resthr maxhr rechr;
	where tolerance='I';
run;
Double Spacing Listing Output
Double Spacing Listing Output
Double Spacing Listing Output

Specifying Titles and Footnotes

Now you've learned how to structure your PRINT procedure output. However, you might also want to make your reports easy to interpret by

  • adding titles and footnotes

  • replacing variable names with descriptive labels

  • formatting variable values.

Although this chapter focuses on PROC PRINT, you can apply these enhancements to most SAS procedure output.

TITLE and FOOTNOTE Statements

To make your report more meaningful and self-explanatory, you can associate up to 10 titles with procedure output by using TITLE statements before the PROC step. Likewise, you can specify up to 10 footnotes by using FOOTNOTE statements before the PROC step.

TITLE and FOOTNOTE Statements

Using the TITLES and FOOTNOTES Windows

You can also specify titles in the TITLES window and footnotes in the FOOTNOTES window. Titles and footnotes that you specify in these windows are not stored with your program, and they remain in effect only during your SAS session.

To open the TITLES window, issue the TITLES command. To open the FOOTNOTES window, issue the FOOTNOTES command.

To specify a title or footnote, type in the text you want next to the number of the line where the text should appear. To cancel a title or footnote, erase the existing text. Notice that you do not enclose text in quotation marks in these windows.

Using the TITLES and FOOTNOTES Windows

Example: Titles

The two TITLE statements below, specified for lines 1 and 3, define titles for the PROC PRINT output.

title1 'Heart Rates for Patients with'; 
title3 'Increased Stress Tolerance Levels';
proc print data=clinic.stress;
   var resthr maxhr rechr;
   where tolerance='I';
run;

Title lines for HTML output appear differently depending on the version of SAS that you use. In SAS Version 8, title lines simply appear consecutively, without extra spacing to indicate skipped title numbers. In SAS®9 HTML output, title line 2 is blank.

Example: Titles

In SAS listing output for all versions of SAS, title line 2 is blank, as shown below. Titles are centered by default.

Example: Titles

Example: Footnotes

The two FOOTNOTE statements below, specified for lines 1 and 3, define footnotes for the PROC PRINT output.

footnote1 'Data from Treadmill Tests'; 
footnote3 '1st Quarter Admissions';
proc print data=clinic.stress;
   var resthr maxhr rechr;
   where tolerance='I';
run;

Footnotes appear at the bottom of each page of procedure output. Notice that footnote lines are pushed up from the bottom. The FOOTNOTE statement that has the largest number appears on the bottom line.

In HTML output, footnote lines simply appear consecutively, without extra spacing to indicate skipped footnote numbers.

Example: Footnotes

In SAS listing output, footnote line 2 is blank, as shown below. Footnotes are centered by default.

Example: Footnotes

Modifying and Canceling Titles and Footnotes

TITLE and FOOTNOTE statements are global statements. That is, after you define a title or footnote, it remains in effect until you modify it, cancel it, or end your SAS session.

For example, the footnotes that are assigned in the PROC PRINT step below also appear in the output from the PROC TABULATE step.

footnote1 'Data from Treadmill Tests'; 
footnote3 '1st Quarter Admissions';
proc print data=clinic.stress;
   var resthr maxhr rechr;
   where tolerance='I';
run;
proc tabulate data=clinic.stress;
   where tolerance='I';
   var resthr maxhr;
   table mean*(resthr maxhr);
run;

Redefining a title or footnote line cancels any higher-numbered title or footnote lines, respectively. In the example below, defining a title for line 2 in the second report automatically cancels title line 3.

title3 'Participation in Exercise Therapy';
proc print data=clinic.therapy;
   var swim walkjogrun aerclass;
run;
title2 'Report for March';
proc print data=clinic.therapy;
run;

To cancel all previous titles or footnotes, specify a null TITLE or FOOTNOTE statement (a TITLE or FOOTNOTE statement with no number or text) or a TITLE1 or FOOTNOTE1 statement with no text. This will also cancel the default title The SAS System.

For example, in the program below, the null TITLE1 statement cancels all titles that are in effect before either PROC step executes. The null FOOTNOTE statement cancels all footnotes that are in effect after the PROC PRINT step executes. The PROC TABULATE output appears without a footnote.

title1; 
footnote1 'Data from Treadmill Tests'; 
footnote3 '1st Quarter Admissions';
proc print data=clinic.stress;
   var resthr maxhr rechr;
   where tolerance='I';
run;
footnote;
proc tabulate data=clinic.stress;
   var timemin timesec;
   table max*(timemin timesec);
run;

Assigning Descriptive Labels

Temporarily Assigning Labels to Variables

You can also enhance your PROC PRINT report by labeling columns with more descriptive text. To label columns, you use

  • the LABEL statement to assign a descriptive label to a variable

  • the LABEL option in the PROC PRINT statement to specify that the labels be displayed.

Example

In the PROC PRINT step below, the variable name WalkJogRun is displayed with the label Walk/Jog/Run. Note the LABEL option in the PROC PRINT statement.

proc print data=clinic.therapy label;
   label walkjogrun='Walk/Jog/Run';
run;
Example

Using Single or Multiple LABEL Statements

You can assign labels in separate LABEL statements . . .

proc print data=clinic.admit label;
   var age height;
   label age='Age of Patient'; 
   label height='Height in Inches';
run;

…oryoucan assign any number of labels in a single LABEL statement.

proc print data=clinic.admit label;
   var actlevel height weight;
label actlevel='Activity Level'
   height='Height in Inches' 
   weight='Weight in Pounds';
run;

Formatting Data Values

Temporarily Assigning Formats to Variables

In your SAS reports, formats control how the data values are displayed. To make data values more understandable when they are displayed in your procedure output, you can use the FORMAT statement, which associates formats with variables.

Formats affect only how the data values appear in output, not the actual data values as they are stored in the SAS data set.

You can use a separate FORMAT statement for each variable, or you can format several variables (using either the same format or different formats) in a single FORMAT statement.

This FORMAT statement …

Associates …

To display values as …

format date mmddyy8.;

the format MMDDYY8. with the variable Date

06/05/03

format net comma5.0
      gross comma8.2;

the format COMMA5.0 with the variable Net and the format COMMA8.2 with the variable Gross

1,234

5,678.90
format net gross dollar9.2;

the format DOLLAR9.2 with both variables, Net and Gross

$1,234.00

$5,678.90

For example, the FORMAT statement below writes values of the variable Fee using dollar signs, commas, and no decimal places.

proc print data=clinic.admit;
   var actlevel fee;
   where actlevel='HIGH';
   format fee dollar4.;
run;
Temporarily Assigning Formats to Variables

Specifying SAS Formats

The table below describes some SAS formats that are commonly used in reports.

Format

Specifies values …

Example

COMMA w.d

that contain commas and decimal places

comma8.2

DOLLAR w.d

that contain dollar signs and commas

dollar6.2

MMDDYY w.

as date values of the form 09/12/97 (MMDDYY8.) or 09/12/1997 (MMDDYY10.)

mmddyy10.

w.

rounded to the nearest integer in w spaces

7.

w.d

rounded to d decimal places in w spaces

8.2

$w.

as character values in w spaces

$12.

DATEw.

as date values of the form 16OCT99 (DATE7.) or 16OCT1999 (DATE9.)

date9.

Field Widths

All SAS formats specify the total field width (w) that is used for displaying the values in the output. For example, suppose the longest value for the variable Net is a four-digit number, such as 5400. To specify the COMMA w.d format for Net, you specify a field width of 5 or more. You must count the comma, because it occupies a position in the output.

Field Widths
Field Widths

Decimal Places

For numeric variables you can also specify the number of decimal places (d), if any, to be displayed in the output. Numbers are rounded to the specified number of decimal places. In the example above, no decimal places are displayed.

Writing the whole number 2030 as 2,030.00 requires eight print positions, including two decimal places and the decimal point.

Decimal Places

Formatting 15374 with a dollar sign, commas, and two decimal places requires ten print positions.

Decimal Places

Examples

This table shows you how data values are displayed when different format, field width, and decimal place specifications are used.

Stored Value

Format Displayed

Value

38245.3975

COMMA12.2

38,245.40

38245.3975

12.2

38245.40

  

$38,245.40

38245.3975

DOLLAR12.2

 

38245.3975

DOLLAR9.2

$38245.40

38245.3975

DOLLAR8.2

38245.40

0

MMDDYY8.

01/01/60

0

MMDDYY10.

01/01/1960

0

DATE7.

01JAN60

0

DATE9.

01JAN1960

Examples

Using Permanently Assigned Labels and Formats

You have seen how to temporarily assign labels and formats to variables. When you use a LABEL or FORMAT statement within a PROC PRINT step, the label or format applies only to the output from that step.

However, in your PROC PRINT steps, you can also take advantage of permanently assigned labels or formats. Permanent labels and formats can be assigned in the DATA step. These labels and formats are saved with the data set, and they can later be used by procedures that reference the data set.

For example, the DATA step below creates Flights.March and defines a format and label for the variable Date. Because the LABEL and FORMAT statements are inside the DATA step, they are written to the Flights.March data set and are available to the subsequent PRINT procedure.

data flights.march;
   set flights.mar01;
   label date='Departure Date'; 
   format date date9.;
run;
proc print data=flights.march label;
run;
Using Permanently Assigned Labels and Formats

Notice that the PROC PRINT statement still requires the LABEL option in order to display the permanent labels. Many other SAS procedures display permanently assigned labels and formats without additional statements or options.

Using Permanently Assigned Labels and Formats

Additional Features

When you create list reports, you can use several other features to enhance your procedure output. For example, you can

  • control where text strings split in labels by using the SPLIT= option.

    proc print data=reps split='*';
       var salesrep type unitsold net commission;
       label salesrep='Sales*Representative';
    run;
  • create your own formats, which are particularly useful for formatting character values.

    proc format; 
       value $repfmt
          'TFB'='Bynum' 
          'MDC'='Crowley' 
          'WKK'='King';
    proc print data=vcrsales;
       var salesrep type unitsold;
       format salesrep $repfmt.;
    run;
    Additional Features

Chapter Summary

Text Summary

Creating a Basic Report

To list the information in a SAS data set, you can use PROC PRINT. You use the PROC PRINT statement to invoke the PRINT procedure and to specify the data set that you are listing. Include the DATA= option to specify the data set that you are using. By default, PROC PRINT displays all observations and variables in the data set, includes a column for observation numbers on the far left, and displays variables in the order in which they occur in the data set. If you use a LABEL statement with PROC PRINT, you must specify the LABEL option in the PROC PRINT statement.

To refine a basic report, you can

  • select which variables and observations are processed

  • sort the data

  • generate column totals for numeric variables.

Selecting Variables

You can select variables and control the order in which they appear by using a VAR statement in your PROC PRINT step. To remove the Obs column, you can specify the NOOBS option in the PROC PRINT statement. As an alternative, you can replace the Obs column with one or more variables by using the ID statement.

Selecting Observations

The WHERE statement enables you to select observations that meet a particular condition in the SAS data set. You use comparison operators to express a condition in the WHERE statement. You can also use the CONTAINS operator to express a condition in the WHERE statement. To specify a condition based on the value of a character variable, you must enclose the value in quotation marks, and you must write the value with lower and uppercase letters exactly as it appears in the data set. You can also use WHERE statements to select a subset of observations based on multiple conditions. To link a sequence of expressions into compound expressions, you use logical operators.

When you test for multiple values of the same variable, you specify the variable name in each expression. You can use the IN operator as a convenient alternative. To control how compound expressions are evaluated, you can use parentheses.

Sorting Data

To display your data in sorted order, you use PROC SORT to sort your data before using PROC PRINT to create reports. By default, PROC SORT sorts the data set specified in the DATA= option permanently. If you do not want your data to be sorted permanently, you must create an output data set that contains the data in sorted order. The OUT= option in the PROC SORT statement specifies an output data set. If you need sorted data to produce output for only one SAS session, you should specify a temporary SAS data set as the output data set. The BY statement, which is required with PROC SORT, specifies the variable(s) whose values are used to sort the data.

Generating Column Totals

To total the values of numeric variables, use the SUM statement in the PROC PRINT step. You do not need to specify the variables in a VAR statement if you specify them in the SUM statement. Column totals appear at the end of the report in the same format as the values of the variables. To produce subtotals, add both the SUM statement and the BY statement to your PROC PRINT step. To show BY variable headings only once, use an ID and BY statement together with the SUM statement. As another enhancement to your report, you can request that each BY group be printed on a separate page by using the PAGEBY statement.

Double Spacing Output

To double space your SAS listing output, you can specify the DOUBLE option.

Specifying Titles

To make your report more meaningful and self-explanatory, you can associate up to 10 titles with procedure output by using TITLE statements anywhere within or preceding the PROC step. After you define a title, it remains in effect until you modify it, cancel it, or end your SAS session. Redefining a title line cancels any higher-numbered title lines. To cancel all previous titles, specify a null TITLE statement (a TITLE statement with no number or text).

Specifying Footnotes

To add footnotes to your output, you can use the FOOTNOTE statement. Like TITLE statements, FOOTNOTE statements are global. Footnotes appear at the bottom of each page of procedure output, and footnote lines are pushed up from the bottom. The FOOTNOTE statement that has the largest number appears on the bottom line. After you define a footnote, it remains in effect until you modify it, cancel it, or end your SAS session. Redefining a footnote line cancels any higher-numbered footnote lines. To cancel all previous footnotes, specify a null FOOTNOTE statement (a FOOTNOTE statement with no number or text).

Assigning Descriptive Labels

To label the columns in your report with more descriptive text, you use the LABEL statement, which assigns a descriptive label to a variable. To display the labels that were assigned in a LABEL statement, you must specify the LABEL option in the PROC PRINT statement.

Formatting Data Values

To make data values more understandable when they are displayed in your procedure output, you can use the FORMAT statement, which associates formats with variables.

The FORMAT statement remains in effect only for the PROC step in which it appears. Formats affect only how the data values appear in output, not the actual data values as they are stored in the SAS data set. All SAS formats specify the total field width (w) that is used for displaying the values in the output. For numeric variables you can also specify the number of decimal places (d), if any, to be displayed in the output.

Using Permanently Assigned Labels and Formats

You can take advantage of permanently assigned labels or formats without adding LABEL or FORMAT statements to your PROC step.

Syntax

LIBNAME libref 'SAS-data-library';

OPTIONS options;

PROC SORT DATA=SAS-data-setOUT=SAS-data-set;

      BY variable(s);

RUN;

TITLE<n> 'text';

FOOTNOTE<n>'text';

PROC PRINT DATA=SAS-data-set

      NOOBS LABEL DOUBLE;

      ID variable(s);

      VAR variable(s);

      WHERE where-expression;

      SUM variable(s);

   LABEL variable1='label1' variable2='label2';

   FORMAT variable(s) format-name;

RUN;

Sample Program

libname clinic 'c:stresslabdata';
options nodate number pageno=15;
proc sort data=clinic.stress out=work.maxrates;
   by maxhr;
run;
proc print data=work.maxrates label double noobs;
   id name;
   var resthr maxhr rechr date;
   where tolerance='I' and resthr>90;
   sum fee;
   label rechr='Recovery HR';
run;
title 'August Admission Fees';
footnote 'For High Activity Patients';
proc print data=clinic.admit label;
   var actlevel fee;
   where actlevel='HIGH';
   label fee='Admission Fee';
   format fee dollar4.;
run;

Points to Remember

  • VAR, WHERE, and SUM statements remain in effect only for the PROC step in which they appear.

  • If you don't use the OUT= option, PROC SORT permanently sorts the data set specified in the DATA= option.

  • TITLE and FOOTNOTE statements remain in effect until you modify them, cancel them, or end your SAS session.

  • Be sure to match the quotation marks that enclose the text in TITLE, FOOTNOTE, and LABEL statements.

  • To display labels in PRINT procedure output, remember to add the LABEL option to the PROC PRINT statement.

  • To permanently assign labels or formats to data set variables, place the LABEL or FORMAT statement inside the DATA step.

Chapter Quiz

Select the best answer for each question. After completing the quiz, you can check your answers using the answer key in the appendix.

  1. Which PROC PRINT step below creates the following output?

    Chapter Quiz
    1. proc print data=flights.laguardia noobs;
      	var on changed flight;
      	where on>=160;
      run;
    2. proc print data=flights.laguardia;
      	var date on changed flight;
      	where changed>3;
      run;
    3. proc print data=flights.laguardia label;
      	id date;
      	var boarded transferred flight;
      	label boarded='On' transferred='Changed';
      	where flight='219';
      run;
    4. proc print flights.laguardia noobs;
      	id date;
      	var date on changed flight;
      	where flight='219';
      run;
  2. Which of the following PROC PRINT steps is correct if labels are not stored with the data set?

    1. proc print data=allsales.totals label;
      	label region8='Region 8 Yearly Totals';
      run;
    2. proc print data=allsales.totals;
      	label region8='Region 8 Yearly Totals';
      run;
    3. proc print data allsales.totals label noobs;
      run;
    4. proc print allsales.totals label;
      run;
  3. Which of the following statements selects from a data set only those observations for which the value of the variable Style is RANCH, SPLIT,or TWOSTORY?

    1. where style='RANCH' or 'SPLIT' or 'TWOSTORY';

    2. where style in 'RANCH' or 'SPLIT' or 'TWOSTORY';

    3. where style in (RANCH, SPLIT, TWOSTORY);

    4. where style in ('RANCH','SPLIT','TWOSTORY'),

  4. If you want to sort your data and create a temporary data set named Calc to store the sorted data, which of the following steps should you submit?

    1. proc sort data=work.calc out=finance.dividend;
      run;
    2. proc sort dividend out=calc;
      	by account;
      run;
    3. proc sort data=finance.dividend out=work.calc;
      	by account;
      run;
    4. proc sort from finance.dividend to calc;
      	by account;
      run;
  5. Which options are used to create the following PROC PRINT output?

    Chapter Quiz
    1. the DATE system option and the LABEL option in PROC PRINT

    2. the DATE and NONUMBER system options and the DOUBLE and NOOBS options in PROC PRINT

    3. the DATE and NONUMBER system options and the DOUBLE option in PROC PRINT

    4. the DATE and NONUMBER system options and the NOOBS option in PROC PRINT

  6. Which of the following statements can you use in a PROC PRINT step to create this output?

    Chapter Quiz
    1. var month instructors;
      sum instructors aerclass walkjogrun swim;
    2. var month;
      sum instructors aerclass walkjogrun swim;
    3. var month instructors aerclass;
      sum instructors aerclass walkjogrun swim;
    4. all of the above

  7. What happens if you submit the following program?

    proc sort data=clinic.diabetes;
    run;
    proc print data=clinic.diabetes;
       var age height weight pulse;
       where sex='F';
    run;
    1. The PROC PRINT step runs successfully, printing observations in their sorted order.

    2. The PROC SORT step permanently sorts the input data set.

    3. The PROC SORT step generates errors and stops processing, but the PROC

      PRINT step runs successfully, printing observations in their original (unsorted) order.

    4. The PROC SORT step runs successfully, but the PROC PRINT step generates errors and stops processing.

  8. If you submit the following program, which output does it create?

    proc sort data=finance.loans out=work.loans;
       by months amount;
    run;
    proc print data=work.loans noobs;
       var months;
       sum amount payment;
       where months<360;
    run;
    1.  

      Chapter Quiz
    2.  

      Chapter Quiz
    3.  

      Chapter Quiz
    4.  

      Chapter Quiz
  9. Choose the statement below that selects rows in which

    • the amount is less than or equal to $5000

    • the account is 101-1092 or the rate equals 0.095.

    1. where amount <= 5000 and
      		account='101-1092' or rate = 0.095;
    2. where (amount le 5000 and account='101-1092')
      		or rate = 0.095;
    3. where amount <= 5000 and
      		(account='101-1092' or rate eq 0.095);
    4. where amount <= 5000 or account='101-1092'
      		and rate = 0.095;
  10. What does PROC PRINT display by default?

    1. PROC PRINT does not create a default report; you must specify the rows and columns to be displayed.

    2. PROC PRINT displays all observations and variables in the data set. If you want an additional column for observation numbers, you can request it.

    3. PROC PRINT displays columns in the following order: a column for observation numbers, all character variables, and all numeric variables.

    4. PROC PRINT displays all observations and variables in the data set, a column for observation numbers on the far left, and variables in the order in which they occur in the data set.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset