Chapter Contents |
Previous |
Next |
The TABULATE Procedure |
Procedure features: |
| |||||
Other features: |
|
To make this crosstabulation of time of day and choice of radio programming, you must have a data set that contains a variable for time of day and a variable for programming preference. PROC TRANSPOSE reshapes the data into a new data set that contains these variables. Once the data are in the appropriate form, PROC TABULATE creates the report.
Collecting the Data |
An external file contains the raw data for the survey. Several lines from that file appear here.
967 32 f 5 3 5 7 5 5 5 7 0 0 0 8 7 0 0 8 0 781 30 f 2 3 5 5 0 0 0 5 0 0 0 4 7 5 0 0 0 859 39 f 1 0 5 1 0 0 0 1 0 0 0 0 0 0 0 0 0 . . . more lines of data . . . 859 32 m .25 .25 1 1 0 0 0 0 0 0 0 1 0 0 0 0 0
Program |
options nodate pageno=1 linesize=132 pagesize=40;
data radio; infile 'input-file' missover; input /(Time1-Time7) ($1. +1); listener=_n_; run; |
proc transpose data=radio out=radio_transposed(rename=(col1=Choice)) name=Timespan; by listener; var time1-time7; |
format timespan $timefmt. choice $pgmfmt.; run; |
proc tabulate data=radio_transposed format=12.; |
class timespan choice; |
table timespan='Time of Day', choice='Choice of Radio Program'*n='Number of Listeners'; |
title 'Listening Preferences on Weekdays'; run; |
Output |
A Closer Look |
PROC TRANSPOSE restructures data so that values that were stored in one observation are written to one variable. You can specify which variables you want to transpose. This section illustrates how PROC TRANSPOSE reshapes the data. The following section explains the PROC TRANSPOSE step in this example.
When you transpose with BY processing, as this example does, you create from each BY group one observation for each variable that you transpose. In this example, Listener is the BY variable. Each observation in the input data set is a BY group because the value of Listener is unique for each observation.
This example transposes seven variables, Time1 through Time7. Therefore, the output data set has seven observations from each BY group (each observation) in the input data set.
Transposing Two Observations uses the first two observations in the input data set to illustrate the transposition.
proc transpose data=radio [1] out=radio_transposed(rename=(col1=Choice)) [2] name=Timespan; [3] by listener; [4] var time1-time7; [5] format timespan $timefmt. choice $pgmfmt.; [6] run;
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.