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

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