Hi!
I'm formatting a variable that is discrete with options from 0 to 10. The variable is a scale on how much the respondent trusts politics with 0 being no trust at all and 10 as complete trust. When I give these values as a format, the 10 does not show up in the frequency table because no respondents answered 10... This is an an issue because then you dont see where the scale ends, is there a way to include this category in the frequency table anyway and just have a 0 as frequency?
thank you!
You talk about frequency table in the title. Do you mean you are using PROC FREQ??? It would help if you could state clearly how you are doing this. Can you show us the code you are using?
Sadly, PROC FREQ doesn't have an easy option for this. If you switch to PROC TABULATE, it has a preloadfmt option that could be used.
For PROC FREQ, see the approach in this answer:
https://communities.sas.com/t5/SAS-Procedures/PROC-FREQ-Include-Zero-Counts/td-p/325505
Also described here:
PROC FREQ with the ZEROS option in the WEIGHT statement can do this.
@PaigeMiller wrote:
PROC FREQ with the ZEROS option in the WEIGHT statement can do this.
Indeed, and that's the approach shown in the answer I linked to. But without PRELOADFMT, it typically requires an extra step to add in the records with zero weight. So there is no 'easy' option you can add to PROC FREQ to say 'give me a table with all the categories defined in a format.'
Extra step yes, but to me it is not a burdensome requirement.
Example: using SASHELP.CLASS, create a frequency table of ages that includes age 17 (there are zero age 17s in the data set)
data class;
set sashelp.class end=eof;
weight=1;
output;
if eof then do;
age=17;
weight=0;
output;
end;
run;
proc freq data=class;
tables age;
weight weight/zeros;
run;
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.