Reputation: 2342
I have Table in SAS Enterprise Guide like below.
Data type:
ID | GROUP |
---|---|
8945 | CON |
9567 | PRI |
9567 | PRI |
284 | CON |
284 | CON |
284 | PRI |
And I need to create new character column "COL1" where:
Generally, PRI is more important group than CON, and if you was at least once in PRI gropu, you have PRI in new COL1. So, as a result I need somethin like below:
ID | COL1 |
---|---|
8945 | CON |
9567 | PRI |
284 | PRI |
How can I do that in SAS Enterprise Guide in PROC SQL or in normal SAS code ?
Upvotes: 0
Views: 105
Reputation: 4937
Try this
data have;
input ID GROUP $;
datalines;
8945 CON
9567 PRI
9567 PRI
284 CON
284 CON
284 PRI
;
proc sql;
create table want as
select distinct *
from have
group by ID
having whichc(GROUP, 'PRI', 'CON')
= min(whichc(GROUP, 'PRI', 'CON'));
quit;
Upvotes: 2