BookmarkSubscribeRSS Feed
steph_
Calcite | Level 5

Hello!

 

I am trying to look at the number of asthma counts by zip code, but when I run the proc freq statement, the zip codes with zero counts of asthma do show up in the results viewer. How can I fix this? Example code below. I have already tried putting 'missing' at the end of the tables step.

 

proc freq data=work.datarequest;
tables zipcode*ASTHMA / norow nocol nopercent;
where ASTHMA=1;
run;

5 REPLIES 5
Tom
Super User Tom
Super User

Don't use the WHERE statement.  That will prevent PROC FREQ from ever seeing the zipcodes that never have ASTHMA=1.

steph_
Calcite | Level 5

Ideally, I wanted to keep the where statement so I do not have to format the data as much. Since I am only interested in Asthma cases.

Tom
Super User Tom
Super User

I cannot visualize what you are trying to do. Can you provide input data and expected results. Just enough data so it demonstrates the issue.  

 

Probably PROC FREQ is not the right tool.  For example PROC SUMMARY (aka MEANS) has methods to allow you to provide information on the complete list of possible values.

Rick_SAS
SAS Super FREQ

 Here is some sample data. For these data, the PROC FREQ step shows only the frequencies for ASTHMA=1. It does not show any cells for missing values.

 

data Have;
infile datalines missover;
input zipcode ASTHMA;
datalines;
12345 1
12345 1
12345 0
12345 
52345 1
52345 1
52345 0
52345 
52345 1
52345 
65432 0
65432 
;

proc freq data=Have;
tables zipcode*ASTHMA / norow nocol nopercent;
where ASTHMA=1;
run;

If this does not answer your question, please modify the input data to mimic the data that you have.

Ksharp
Super User
First way is trying SPARSE option:
proc freq data=work.datarequest;
tables zipcode*ASTHMA / norow nocol nopercent sparse ;
run;

Second way is using WEIGHT statement @Rick_SAS mentioned this skill in one of his blog. Post your sample data that would be better to demonstrate how to use WEIGHT .

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 642 views
  • 1 like
  • 4 in conversation