BookmarkSubscribeRSS Feed
meesbots
Calcite | Level 5

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!

5 REPLIES 5
PaigeMiller
Diamond | Level 26

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?

--
Paige Miller
Quentin
Super User

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:

https://stats.oarc.ucla.edu/sas/faq/how-can-i-include-cells-with-zero-counts-in-proc-freq-with-the-l...

 

PaigeMiller
Diamond | Level 26

PROC FREQ with the ZEROS option in the WEIGHT statement can do this.

--
Paige Miller
Quentin
Super User

@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.'

PaigeMiller
Diamond | Level 26

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;
--
Paige Miller

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1803 views
  • 0 likes
  • 3 in conversation