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

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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