BookmarkSubscribeRSS Feed
kparker
Quartz | Level 8

I'm fairly new to SAS but was wondering if there is a way to delete observations by frequency count?  For example, I used proc freq to generate a count of all diagnosis codes but all frequency counts<=5, I want to remove from the dataset.  Is this possible?

3 REPLIES 3
Steelers_In_DC
Barite | Level 11

There's going to be a lot of different ways to get this result.  One way is to use the out= statement in your proc freq.  This will get you a dataset with the result that you can manipulate anyway you want:

proc freq data= have;table variable /out=want;

kparker
Quartz | Level 8

For example,

I have over 500,000 observations in this dataset.

I already have my data filtered for the columns I need but for the diagnosis column, I ran a proc freq.

My Proc Freq data looks like:

DIAGNOSIS_PRIN_CDFrequencyDIAGNOSIS_PRIN_CDFrequencyV300032677V3001211094861568338910455V300032677V30012110948615683389104557778279153767218615

I want to suppress or result any diagnosis code that has a frequency count <=5 with Blank or '.'

I am thinking about creating a data step and using IF-THEN statements to accomplish this task but it will be very time consuming.

PGStats
Opal | Level 21

proc freq might not be the best tool for data management. I would use proc SQL :

proc sql;

create table want as

select * from have

group by diagnosisCode

having count(*) > 5;

quit;

PG

PG

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