Features: |
TABLE statement: N statistic |
Other features: |
FORMAT procedure TRANSPOSE procedure Data set options: RENAME= |
Data set: | RADIO |
data radio;
infile 'input-file' missover;
input /(Time1-Time7) ($1. +1); listener=_n_; run;
proc format; value $timefmt 'Time1'='6-9 a.m.' 'Time2'='9 a.m. to noon' 'Time3'='noon to 1 p.m.' 'Time4'='1-4 p.m.' 'Time5'='4-6 p.m.' 'Time6'='6-10 p.m.' 'Time7'='10 p.m. to 2 a.m.' other='*** Data Entry Error ***'; value $pgmfmt '0'="Don't Listen" '1','2'='Rock and Top 40' '3'='Country' '4','5','6'='Jazz, Classical, and Easy Listening' '7'='News/ Information /Talk' '8'='Other' other='*** Data Entry Error ***'; run;
proc transpose data=radio out=radio_transposed(rename=(col1=Choice)) name=Timespan; by listener; var time1-time7; run;
proc tabulate data=radio_transposed format=12.;
format timespan $timefmt. choice $pgmfmt.;
class timespan choice;
table timespan='Time of Day', choice='Choice of Radio Program'*n='Number of Listeners';
title 'Listening Preferences on Weekdays'; run;
proc format; value $timefmt 'Time1'='6-9 a.m.' 'Time2'='9 a.m. to noon' 'Time3'='noon to 1 p.m.' 'Time4'='1-4 p.m.' 'Time5'='4-6 p.m.' 'Time6'='6-10 p.m.' 'Time7'='10 p.m. to 2 a.m.' other='*** Data Entry Error ***'; value $pgmfmt '0'="Don't Listen" '1','2'='Rock and Top 40' '3'='Country' '4','5','6'='Jazz, Classical, and Easy Listening' '7'='News/ Information /Talk' '8'='Other' other='*** Data Entry Error ***'; run;
proc transpose data=radio out=radio_transposed(rename=(col1=Choice)) name=Timespan; by listener; var time1-time7; run;
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;
1 | The DATA= option specifies the input data set. |
2 | The OUT= option specifies the output data set. The RENAME= data set option renames the transposed variable from COL1 (the default name) to Choice. |
3 | The NAME= option specifies the name for the variable in the output data set that contains the name of the variable that is being transposed to create the current observation. By default, the name of this variable is _NAME_. |
4 | The BY statement identifies Listener as the BY variable. |
5 | The VAR statement identifies Time1 through Time7 as the variables to transpose. |
6 | The FORMAT statement assigns formats to Timespan and Choice. The PROC TABULATE step that creates the report does not need to format Timespan and Choice because the formats are stored with these variables. |