When using proc freq, what code is needed to include levels with frequencies equaling 0 in your output?
Thanks!
@hein68 wrote:
When using proc freq, what code is needed to include levels with frequencies equaling 0 in your output?
Thanks!
I think you need to be a bit more detailed in your question such as providing some example data and exactly what "level" that has a frequency of 0 that should be counted.
Are you talking about a combination of variables or a single variable?
Hi @hein68,
Another trick is to use the WEIGHT statement with the ZEROS option:
/* Create test data for demonstration */
data have;
set sashelp.class;
run;
/* Introduce age levels with frequency zero */
data want / view=want;
do until(last);
set have end=last;
_w=1;
output;
end;
do age=5, 18, 99;
_w=0;
output;
end;
run;
/* Create frequency table including the new levels */
proc freq data=want;
weight _w / zeros;
tables age;
run;
Output:
Cumulative Cumulative Age Frequency Percent Frequency Percent -------------------------------------------------------- 5 0 0.00 0 0.00 11 2 10.53 2 10.53 12 5 26.32 7 36.84 13 3 15.79 10 52.63 14 4 21.05 14 73.68 15 4 21.05 18 94.74 16 1 5.26 19 100.00 18 0 0.00 19 100.00 99 0 0.00 19 100.00
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.