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

 

The Boston Area SAS Users Group (BASUG) is hosting our in person SAS Blowout on Oct 18!
This full-day event in Cambridge, Mass features four presenters from SAS, presenting on a range of SAS 9 programming topics. Pre-registration by Oct 15 is required.
Full details and registration info at https://www.basug.org/events.
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.'

The Boston Area SAS Users Group (BASUG) is hosting our in person SAS Blowout on Oct 18!
This full-day event in Cambridge, Mass features four presenters from SAS, presenting on a range of SAS 9 programming topics. Pre-registration by Oct 15 is required.
Full details and registration info at https://www.basug.org/events.
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

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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