BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Rodolfo_Mingoti
Fluorite | Level 6

Hi, I would like help to filter my database. My database contains 1000 observations. The input data are:

OBSCOW_IDTREATMENTBULL PREGNANCY
2Cow_2BBULL_D1
3Cow_3CBULL_B1
4Cow_4BBULL_C0
5Cow_5CBULL_H1
6Cow_6ABULL_F0
7Cow_7CBULL_H1
8Cow_8BBULL_B1
9Cow_9ABULL_D1
10Cow_10ABULL_B1

Would like to remove bulls who has frequency less than 50 observations, that is, keep only the bulls with frequency higher than 50 observations.

 

My strategy was to use PROC FREQ and find bulls with frequencies below 50 observations. The next step was to use the IF/THEN/DELETE statements to filter the database manually.

I wonder if anyone has an alternative idea to reduce manual labor and make it automatic.

I share the database and the procedures that I used, to understand the steps by steps.

 

/*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------*/
proc freq data=work.bull_diagnosis order=freq;
table Treatment Bull / nopercent nocol nocum ;
run;
/*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------*/
Data Bull_filtered;
set work.bull_diagnosis;

     if BULL = "BULL_A"  then delete;
     if BULL = "BULL_G" then delete;
     if BULL = "BULL_J"  then delete;
     if BULL = "BULL_I"   then delete;
     if BULL = "BULL_E" then delete;

run;
quit;
/*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------*/
proc freq data=work.bull_filtered order=freq;
table Treatment Bull / nopercent nocol nocum ;
run;
/*----------------------------------------------------------------------------*/

 

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
proc sql;
create table want as
select * from work.bull_diagnosis
group by bull
having count(*)>50 ;
quit;

View solution in original post

2 REPLIES 2
Ksharp
Super User
proc sql;
create table want as
select * from work.bull_diagnosis
group by bull
having count(*)>50 ;
quit;
Rodolfo_Mingoti
Fluorite | Level 6

Thank you very much Ksharp ... it worked perfectly!
The problem was solved!!!

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
  • 2 replies
  • 610 views
  • 0 likes
  • 2 in conversation