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?

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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