BookmarkSubscribeRSS Feed
captainprice0
Fluorite | Level 6

Hi,

 

I have table of this structure with more than 1 flags, (have just 1 flag here for simplicity).

 

How do I create another table with no 'case 3' in it? 

I want to remove all cases where FLAG_1 is 0(for all occurrence of that case), but not those where it's either 0,1 or 1

 

One option I can think of is by using MAX(FLAG_1) with group by 'Key' to create a table and then do right join. But I have several FLAG columns such as these and looking for some R, Python type of solution for concision.

 

KeyFLAG_1Conclusion
case 20include
case 20include
case 21include
case 21include
case 30remove
case 30remove
case 30remove
case 41include

 

3 REPLIES 3
SASKiwi
PROC Star

So is there any problem with just doing a simple not equal to?

where key ne 'case 3';
captainprice0
Fluorite | Level 6

haha!

 

actually there are millions of 'Key' in my datasets, case 1,2, and 3 are just an example.

 

I need to logically identify them, based on the presence of FLAG column.

 

As FLAG will either have '1' or '0' in them, but they are not uniform across all instance of cases.

captainprice0
Fluorite | Level 6

If I were to do this in R let's say,

I would write a max() function which will generate a table with distinct Key and there corresponding maximum value.

 

To do this in SQL would require me to write a groub by statement on Key with select MAX(FLAG_1)
but I will have to repeat this for all instances of FLAG I have and then join these tables.

 

Is there a way of doing this quickly in SAS?

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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