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.
Key | FLAG_1 | Conclusion |
case 2 | 0 | include |
case 2 | 0 | include |
case 2 | 1 | include |
case 2 | 1 | include |
case 3 | 0 | remove |
case 3 | 0 | remove |
case 3 | 0 | remove |
case 4 | 1 | include |
So is there any problem with just doing a simple not equal to?
where key ne 'case 3';
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.
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?
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!
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.