PROC FREQ does not have a PRELOADFMT option like the MEANS and TABULATE procedures. You can add a missing category to the data and create a weight variable with a value of zero to that observation and a value of one for all other observations. Then use the WEIGHT statement with the ZEROS option in PROC FREQ to display the small value as zero. In this example, name='CC' does not intially exist in the data set.
Prior to SAS 9, you would need to create a user-defined format and modify the Base.Freq.OneWayList template to successfully display the missing category because the ZEROS option was not yet available. This would also require that the weight variable value for the missing category be a very small value rather than zero.
See the Full Code tab for illustrations of both methods.
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.
/********************************************/
/** SAS 9 Method **/
/********************************************/
/* Just creating a sample data set here */
data test;
length name $ 8;
do name='AA','BB';
do status=1 to 3;
do i=1 to 3;
do j=1 to int(ranuni(i)*24);
output;
end; end; end; end;
run;
/* Add name of CC to end of data set */
/* with a weight of zero */
data test;
set test end=eof;
wt=1;
output;
if eof then do;
name='CC';
wt=0;
output;
end;
run;
/* Use weight statement */
proc freq data=test;
tables name / out=out1;
weight wt / zeros;
run;
/********************************************/
/** SAS 8 Method **/
/********************************************/
/* Just creating a sample data set here */
data test;
length name $ 8;
do name='AA','BB';
do status=1 to 3;
do i=1 to 3;
do j=1 to int(ranuni(i)*24);
output;
end; end; end; end;
run;
/* Add name of CC to end of data set */
/* with a very small weight */
data test;
set test end=eof;
wt=1;
output;
if eof then do;
name='CC';
wt=1E-13;
output;
end;
run;
/* Create format to display values <1 as 0 */
proc format;
value maskf low-<1=' 0'
other=[8.];
run;
ods path reset;
ods path (prepend) work.templat(update);
/* Modify default template to display Frequency count */
/* with a different format. */
proc template;
edit Base.Freq.OneWayList;
edit frequency;
format=maskf.;
end;
end;
/* Use weight statement */
proc freq data=test;
tables name / out=out1;
weight wt ;
run;
/* To see actual frequency count */
proc print data=out1;
format count 32.25;
run;
proc template;
delete Base.Freq.OneWayList;
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.
The FREQ Procedure Cumulative Cumulative name Frequency Percent Frequency Percent --------------------------------------------------------- AA 113 52.07 113 52.07 BB 104 47.93 217 100.00 CC 0 0.00 217 100.00
Type: | Sample |
Topic: | SAS Reference ==> Procedures ==> FREQ Analytics ==> Nonparametric Analysis Analytics ==> Longitudinal Analysis Analytics ==> Descriptive Statistics Analytics ==> Exact Methods Analytics ==> Categorical Data Analysis |
Date Modified: | 2019-07-30 09:33:10 |
Date Created: | 2005-01-26 16:16:22 |
Product Family | Product | Host | SAS Release | |
Starting | Ending | |||
SAS System | Base SAS | All | 8 TS M0 | n/a |