Sample 37780: Reshape PROC FREQ OneWayFreqs output data set in SAS® 9
Using an ODS OUTPUT statement with a PROC FREQ step enables you to output
results from multiple one-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 be in 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 be in a more readable, tabular format.
ods listing close;
ods output OneWayFreqs=outfreq;
proc freq data=sashelp.class;
tables age sex;
run;
ods output close;
ods listing;
proc print data=outfreq label;
run;
/* This DATA step reshapes the output data set to a more tabular format. */
data allfreq;
retain table column_value;
set outfreq;
keep table column_value frequency percent cumfrequency cumpercent;
table=scan(table,2,' ');
column_value=trim(left(vvaluex(table)));
label table='Table'
column_value='Column_Value';
run;
proc print data=allfreq label;
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.
Column_ Cumulative Cumulative
Obs Table Value Frequency Percent Frequency Percent
1 Age 11 2 10.53 2 10.53
2 Age 12 5 26.32 7 36.84
3 Age 13 3 15.79 10 52.63
4 Age 14 4 21.05 14 73.68
5 Age 15 4 21.05 18 94.74
6 Age 16 1 5.26 19 100.00
7 Sex F 9 47.37 9 47.37
8 Sex M 10 52.63 19 100.00
How to reshape a OneWayFreqs output data set to a more readable, tabular format.
Date Modified: | 2019-06-10 09:12:24 |
Date Created: | 2009-11-10 15:22:36 |
Operating System and Release Information
SAS System | Base SAS | Microsoft Windows Server 2003 Enterprise 64-bit Edition | 9 TS M0 | |
Microsoft Windows Server 2003 Datacenter 64-bit Edition | 9 TS M0 | |
Microsoft® Windows® for 64-Bit Itanium-based Systems | 9 TS M0 | |
Microsoft Windows 2000 Advanced Server | 9 TS M0 | |
Tru64 UNIX | 9 TS M0 | |
OpenVMS Alpha | 9 TS M0 | |
Linux | 9 TS M0 | |
HP-UX IPF | 9 TS M0 | |
64-bit Enabled Solaris | 9 TS M0 | |
64-bit Enabled HP-UX | 9 TS M0 | |
64-bit Enabled AIX | 9 TS M0 | |
Microsoft Windows XP Professional | 9 TS M0 | |
Microsoft Windows Server 2003 Standard Edition | 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 Server 2003 Datacenter Edition | 9 TS M0 | |
Microsoft Windows NT Workstation | 9 TS M0 | |
Microsoft Windows Server 2003 Enterprise Edition | 9 TS M0 | |
z/OS | 9 TS M0 | |