I have table in SAS Enterprise Guide like below:
ID | COL1 |
---|---|
123 | 1 |
123 | 0 |
123 | 0 |
444 | 1 |
444 | 0 |
778 | 0 |
And I need to aggregate above table and create column 'TARGET':
TARGET = 1 for these IDs which at least once have '1' in the column 'COL1'
TARGET = 0 for these IDs which have never had a '1' in the column 'COL1'
Moreover I need to delete duplicates in ID
, so as a result i need something like below :
ID | TARGET |
---|---|
123 | 1 -> had '1' at least once in COL1 |
444 | 1 -> had '1' at least once in COL1 |
778 | 0 -> never had '1' in COL1 |
How can I do that in SAS Enterprise Guide in normal SAS code or in PROC SQL ?
Your logic is equivalent to taking the maximum value of the column for each ID.
proc sql;
create table want as
select ID, max(col1) as Target
from have
group by ID;
quit;