Sample 37782: Reshape PROC FREQ CrossTabFreqs output data set in SAS® 9
Using an ODS OUTPUT statement with a PROC FREQ step enables you to output
results from multiple two-way table requests to one SAS data set. The code
included in the Full Code tab demonstrates a DATA step method for reshaping
that output data set to a more readable, tabular format.
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
The code below demonstrates a DATA step method for reshaping the output data set from PROC FREQ to a more readable, tabular format.
data class;
/* Creating additional variable for CrossTabFreqs example */
set sashelp.class;
if mod(_N_,2)=0 then group=1;
else group=2;
run;
ods listing close;
ods output CrossTabfreqs=outfreq (where=(_type_='11'));
proc freq data=class;
tables sex*(group age);
run;
ods output close;
ods listing;
data allfreq;
length table $ 25;
length column_value1 column_value2 $ 10;
retain table column_value1 column_value2;
set outfreq;
keep table column_value1 column_value2
frequency percent rowpercent colpercent;
table1=scan(table,2,' ');
table2=scan(table,4,' ');
table=substr(table,7);
column_value1=trim(left(vvaluex(table1)));
column_value2=trim(left(vvaluex(table2)));
label table='Table';
run;
proc print data=allfreq label noobs;
format percent rowpercent colpercent 8.1;
run;
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
Percent of
Two-Way Percent Percent of
column_ column_ Frequency Table of Row Column
Table value1 value2 Count Frequency Frequency Frequency
Sex * group F 1 5 26.3 55.6 55.6
Sex * group F 2 4 21.1 44.4 40.0
Sex * group M 1 4 21.1 40.0 44.4
Sex * group M 2 6 31.6 60.0 60.0
Sex * Age F 11 1 5.3 11.1 50.0
Sex * Age F 12 2 10.5 22.2 40.0
Sex * Age F 13 2 10.5 22.2 66.7
Sex * Age F 14 2 10.5 22.2 50.0
Sex * Age F 15 2 10.5 22.2 50.0
Sex * Age F 16 0 0.0 0.0 0.0
Sex * Age M 11 1 5.3 10.0 50.0
Sex * Age M 12 3 15.8 30.0 60.0
Sex * Age M 13 1 5.3 10.0 33.3
Sex * Age M 14 2 10.5 20.0 50.0
Sex * Age M 15 2 10.5 20.0 50.0
Sex * Age M 16 1 5.3 10.0 100.0
How to reshape a CrossTabFreqs output data set to a more readable, tabular format.
Date Modified: | 2019-03-05 12:50:19 |
Date Created: | 2009-11-10 15:40:19 |
Operating System and Release Information
SAS System | Base SAS | Microsoft® Windows® for 64-Bit Itanium-based Systems | 9 TS M0 | |
z/OS | 9 TS M0 | |
Microsoft Windows Server 2003 Datacenter 64-bit Edition | 9 TS M0 | |
Microsoft Windows Server 2003 Enterprise 64-bit Edition | 9 TS M0 | |
Microsoft Windows 2000 Advanced Server | 9 TS M0 | |
Microsoft Windows 2000 Datacenter Server | 9 TS M0 | |
Microsoft Windows 2000 Server | 9 TS M0 | |
Microsoft Windows 2000 Professional | 9 TS M0 | |
Microsoft Windows NT Workstation | 9 TS M0 | |
Microsoft Windows Server 2003 Datacenter Edition | 9 TS M0 | |
Microsoft Windows Server 2003 Enterprise Edition | 9 TS M0 | |
Microsoft Windows Server 2003 Standard Edition | 9 TS M0 | |
Microsoft Windows XP Professional | 9 TS M0 | |
64-bit Enabled AIX | 9 TS M0 | |
64-bit Enabled HP-UX | 9 TS M0 | |
64-bit Enabled Solaris | 9 TS M0 | |
HP-UX IPF | 9 TS M0 | |
Linux | 9 TS M0 | |
OpenVMS Alpha | 9 TS M0 | |
Tru64 UNIX | 9 TS M0 | |