SAS Programming

DATA Step, Macro, Functions and more
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 is hosting free webinars!
Next up: Troy Martin Hughes presents Calling Open-Source Python Functions within SAS PROC FCMP: A Google Maps API Geocoding Adventure on Wednesday April 23.
Register now 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 is hosting free webinars!
Next up: Troy Martin Hughes presents Calling Open-Source Python Functions within SAS PROC FCMP: A Google Maps API Geocoding Adventure on Wednesday April 23.
Register now 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-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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
  • 1521 views
  • 0 likes
  • 3 in conversation