<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Combining duplicate id's based on different variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Combining-duplicate-id-s-based-on-different-variables/m-p/820834#M324023</link>
    <description>&lt;P&gt;I have multiple observations per person. What I'm trying to do is if COMPDT = '.' for all rows for that same ID, then I just want to keep one of the obs(they're duplicates in this case). However, if COMPFL='Y' then I want ESDT=COMPDT and ETDT=ETDT where&amp;nbsp;&lt;/P&gt;&lt;P&gt;DSSEQ =1 for that id. How can I do this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Current data&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;ID    DSSEQ    ESDT         ETDT          COMPFL   COMPDT
001     1      01Jan2016    01Jan2016       N        .
001     2      01Jan2016    01Jan2016       N        .
002     4      07JUL2014    07JUL2014       N        .  
002     2      13NOV2012    13NOV2012       Y      13NOV2012
002     3      06DEC2018    06DEC2018       N        .
002     1      14FEB2020    14FEB2020       N        .
003     2       25OCT2018   25OCT2018       N        .       
003     1       25OCT2018   25OCT2018       N        .      &lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Wanted data&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;ID    DSSEQ    ESDT         ETDT          
001     1      01Jan2016    01Jan2016              
002     2      13NOV2012    14FEB2020            
003     1       25OCT2018   25OCT2018             &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 29 Jun 2022 00:02:03 GMT</pubDate>
    <dc:creator>nharuka</dc:creator>
    <dc:date>2022-06-29T00:02:03Z</dc:date>
    <item>
      <title>Combining duplicate id's based on different variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combining-duplicate-id-s-based-on-different-variables/m-p/820834#M324023</link>
      <description>&lt;P&gt;I have multiple observations per person. What I'm trying to do is if COMPDT = '.' for all rows for that same ID, then I just want to keep one of the obs(they're duplicates in this case). However, if COMPFL='Y' then I want ESDT=COMPDT and ETDT=ETDT where&amp;nbsp;&lt;/P&gt;&lt;P&gt;DSSEQ =1 for that id. How can I do this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Current data&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;ID    DSSEQ    ESDT         ETDT          COMPFL   COMPDT
001     1      01Jan2016    01Jan2016       N        .
001     2      01Jan2016    01Jan2016       N        .
002     4      07JUL2014    07JUL2014       N        .  
002     2      13NOV2012    13NOV2012       Y      13NOV2012
002     3      06DEC2018    06DEC2018       N        .
002     1      14FEB2020    14FEB2020       N        .
003     2       25OCT2018   25OCT2018       N        .       
003     1       25OCT2018   25OCT2018       N        .      &lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Wanted data&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;ID    DSSEQ    ESDT         ETDT          
001     1      01Jan2016    01Jan2016              
002     2      13NOV2012    14FEB2020            
003     1       25OCT2018   25OCT2018             &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Jun 2022 00:02:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combining-duplicate-id-s-based-on-different-variables/m-p/820834#M324023</guid>
      <dc:creator>nharuka</dc:creator>
      <dc:date>2022-06-29T00:02:03Z</dc:date>
    </item>
    <item>
      <title>Re: Combining duplicate id's based on different variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combining-duplicate-id-s-based-on-different-variables/m-p/820860#M324032</link>
      <description>&lt;P&gt;Assuming that every ID has exactly one DSSEQ=1 record, and that any ID which has a non-missing COMPDT has only one such record, then a self-MERGE with a selective KEEP parameter will work just fine:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want (drop=compfl compdt);
  merge have (where=(dsseq=1))
        have (keep=id dsseq compdt where=(compdt^=.));
  by id;
  if compdt^=. then esdt=compdt;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This also assume data are sorted by ID.&lt;/P&gt;</description>
      <pubDate>Wed, 29 Jun 2022 05:14:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combining-duplicate-id-s-based-on-different-variables/m-p/820860#M324032</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2022-06-29T05:14:17Z</dc:date>
    </item>
  </channel>
</rss>

