TABULATE Procedure

Example 10: Reporting on Multiple-Response Survey Data

Features:
TABLE statement:
denominator definition (angle bracket operators)
N statistic
PCTN statistic
variable list
Other features:

FORMAT procedure

SAS system options:
FORMDLIM=
NONUMBER

SYMPUT routine

Data set: CUSTOMER_RESPONSE

Details

The two tables in this example show the following:
  • which factors most influenced customers' decisions to buy products
  • where customers heard of the company
The reports appear on one physical page with only one page number. By default, they would appear on separate pages.
In addition to showing how to create these tables, this example shows how to do the following:
  • use a DATA step to count the number of observations in a data set
  • store that value in a macro variable
  • access that value later in the SAS session

Collecting the Data

The following figure shows the survey form that is used to collect data.
Completed Survey Form
Completed Survey Form

Program

data customer_response;
   input Customer Factor1-Factor4 Source1-Source3
         Quality1-Quality3;
   datalines;
1 . . 1 1 1 1 . 1 . .
2 1 1 . 1 1 1 . 1 1 .
3 . . 1 1 1 1 . . . .

. . . more data lines . . .

119 . . . 1 . . . 1 . .
120 1 1 . 1 . . . . 1 .
;
data _null_;
   if 0 then set customer_response nobs=count;
   call symput('num',left(put(count,4.)));
   stop;
run;
proc format;
   picture pctfmt low-high='009.9 %';
run;
proc tabulate data=customer_response;
   var factor1-factor4 customer;
   table factor1='Cost'
         factor2='Performance'
         factor3='Reliability'
         factor4='Sales Staff',
         (n='Count'*f=7. pctn<customer>='Percent'*f=pctfmt9.) ;
   title 'Customer Survey Results: Spring 1996';
   title3 'Factors Influencing the Decision to Buy';
run;
proc tabulate
data=customer_response;
   var source1-source3 customer;
   table source1='TV/Radio'
         source2='Newspaper'
         source3='Word of Mouth',
         (n='Count'*f=7. pctn<customer>='Percent'*f=pctfmt9.) ;
   title 'Source of Company Name';
   footnote "Number of Respondents: &num";
run;
options formdlim='' number;

Program Description

Create the CUSTOMER_RESPONSE data set.CUSTOMER_RESPONSE contains data from a customer survey. Each observation in the data set contains information about factors that influence one respondent's decisions to buy products. A DATA step creates the data set. Using missing values rather than 0s is crucial for calculating frequency counts in PROC TABULATE.
data customer_response;
   input Customer Factor1-Factor4 Source1-Source3
         Quality1-Quality3;
   datalines;
1 . . 1 1 1 1 . 1 . .
2 1 1 . 1 1 1 . 1 1 .
3 . . 1 1 1 1 . . . .

. . . more data lines . . .

119 . . . 1 . . . 1 . .
120 1 1 . 1 . . . . 1 .
;
Store the number of observations in a macro variable.The SET statement reads the descriptor portion of CUSTOMER_RESPONSE at compile time and stores the number of observations (the number of respondents) in COUNT. The SYMPUT routine stores the value of COUNT in the macro variable NUM. This variable is available for use by other procedures and DATA steps for the remainder of the SAS session. The IF 0 condition, which is always false, ensures that the SET statement, which reads the observations, never executes. (Reading observations is unnecessary.) The STOP statement ensures that the DATA step executes only once.
data _null_;
   if 0 then set customer_response nobs=count;
   call symput('num',left(put(count,4.)));
   stop;
run;
Create the PCTFMT. format.The FORMAT procedure creates a format for percentages. The PCTFMT. format writes all values with at least one digit to the left of the decimal point and with one digit to the right of the decimal point. A blank and a percent sign follow the digits.
proc format;
   picture pctfmt low-high='009.9 %';
run;
Create the report and use the default table options.
proc tabulate data=customer_response;
Specify the analysis variables.The VAR statement specifies that PROC TABULATE calculate statistics on the Factor1, Factor2, Factor3, Factor4, and Customer variables. The variable Customer must be listed because it is used to calculate the Percent column that is defined in the TABLE statement.
   var factor1-factor4 customer;
Define the table rows and columns.The TABLE statement creates a row for each factor, a column for frequency counts, and a column for the percentages. Text in quotation marks supplies headings for the corresponding row or column. The format modifiers F=7. and F=PCTFMT9. provide formats for values in the associated cells and extend the column widths to accommodate the column headings.
   table factor1='Cost'
         factor2='Performance'
         factor3='Reliability'
         factor4='Sales Staff',
         (n='Count'*f=7. pctn<customer>='Percent'*f=pctfmt9.) ;
Specify the titles.
   title 'Customer Survey Results: Spring 1996';
   title3 'Factors Influencing the Decision to Buy';
run;
Create the report and use the default table options.
proc tabulate
data=customer_response;
Specify the analysis variables.The VAR statement specifies that PROC TABULATE calculate statistics on the Source1, Source2, Source3, and Customer variables. The variable Customer must be in the variable list because it appears in the denominator definition.
   var source1-source3 customer;
Define the table rows and columns.The TABLE statement creates a row for each source of the company name, a column for frequency counts, and a column for the percentages. Text in quotation marks supplies a heading for the corresponding row or column.
   table source1='TV/Radio'
         source2='Newspaper'
         source3='Word of Mouth',
         (n='Count'*f=7. pctn<customer>='Percent'*f=pctfmt9.) ;
Specify the title and footnote.The macro variable NUM resolves to the number of respondents. The FOOTNOTE statement uses double rather than single quotation marks so that the macro variable will resolve.
   title 'Source of Company Name';
   footnote "Number of Respondents: &num";
run;
Reset the SAS system options.The FORMDLIM= option resets the page delimiter to a page eject. The NUMBER option resumes the display of page numbers on subsequent pages.
options formdlim='' number;

Output

Customer Survey Results: Spring 1996