sasproc-sqlenterprise-guide

How to create binary column base on values in other column and drop duplicates in SAS Enterprise Guide 4GL / PROC SQL?


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':

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 ?


Solution

  • 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;