<?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 Re: If duplicate, add flag in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/If-duplicate-add-flag/m-p/337558#M76668</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have;
by id;
run;

data want;
set have;
by id;

flag=1;
if first.id and last.id then flag=0; *change flag for unique records;

*flag=0;
*if not (first.id and last.id) flag=1; *change flag for duplicate records;

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 02 Mar 2017 20:42:13 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2017-03-02T20:42:13Z</dc:date>
    <item>
      <title>If duplicate, add flag</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-duplicate-add-flag/m-p/337550#M76662</link>
      <description>&lt;P&gt;hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;does anyone know how i can flag for duplicate value? I'd like to create a dummy variable where if variable is a duplicate, dummy_var=1, else 0...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the variable contains char value.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example output:&lt;/P&gt;&lt;P&gt;IDs &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Dummy_Var&lt;/P&gt;&lt;P&gt;a010 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;a010 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;a011 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;&lt;P&gt;a012 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;a012 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Thu, 02 Mar 2017 20:24:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-duplicate-add-flag/m-p/337550#M76662</guid>
      <dc:creator>brulard</dc:creator>
      <dc:date>2017-03-02T20:24:56Z</dc:date>
    </item>
    <item>
      <title>Re: If duplicate, add flag</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-duplicate-add-flag/m-p/337551#M76663</link>
      <description>&lt;P&gt;Try this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data t;
input ID$;
cards;
a010
a010
a011
a012
a012
;
run;

data t2;
set t;
by ID;
DupFlag=  first.ID ne last.ID; 
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 Mar 2017 20:30:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-duplicate-add-flag/m-p/337551#M76663</guid>
      <dc:creator>nehalsanghvi</dc:creator>
      <dc:date>2017-03-02T20:30:47Z</dc:date>
    </item>
    <item>
      <title>Re: If duplicate, add flag</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-duplicate-add-flag/m-p/337552#M76664</link>
      <description>&lt;P&gt;That solution would work for the given data, but would fail when you have 3 or more observations for the same ID.&amp;nbsp; There are many ways to come up with a more robust program, such as:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;by id;&lt;/P&gt;
&lt;P&gt;if first.id=0 or last.id=0 then flag=1;&lt;/P&gt;
&lt;P&gt;else flag=0;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Mar 2017 20:32:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-duplicate-add-flag/m-p/337552#M76664</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-03-02T20:32:52Z</dc:date>
    </item>
    <item>
      <title>Re: If duplicate, add flag</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-duplicate-add-flag/m-p/337553#M76665</link>
      <description>&lt;P&gt;hi&amp;nbsp;nehalsanghvi ,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks for tip... I should have mentioned, my data can have more than 1 duplicate&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example output:&lt;/P&gt;&lt;P&gt;IDs &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Dummy_Var&lt;/P&gt;&lt;P&gt;a010 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;a010 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;a010 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;a010 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;a011 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;&lt;P&gt;a012 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;a012 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;</description>
      <pubDate>Thu, 02 Mar 2017 20:34:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-duplicate-add-flag/m-p/337553#M76665</guid>
      <dc:creator>brulard</dc:creator>
      <dc:date>2017-03-02T20:34:02Z</dc:date>
    </item>
    <item>
      <title>Re: If duplicate, add flag</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-duplicate-add-flag/m-p/337557#M76667</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data t2;
set t;
by ID;
DupFlag=  ^(first.ID and last.ID); 
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 Mar 2017 20:36:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-duplicate-add-flag/m-p/337557#M76667</guid>
      <dc:creator>nehalsanghvi</dc:creator>
      <dc:date>2017-03-02T20:36:17Z</dc:date>
    </item>
    <item>
      <title>Re: If duplicate, add flag</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-duplicate-add-flag/m-p/337558#M76668</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have;
by id;
run;

data want;
set have;
by id;

flag=1;
if first.id and last.id then flag=0; *change flag for unique records;

*flag=0;
*if not (first.id and last.id) flag=1; *change flag for duplicate records;

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Mar 2017 20:42:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-duplicate-add-flag/m-p/337558#M76668</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-03-02T20:42:13Z</dc:date>
    </item>
    <item>
      <title>Re: If duplicate, add flag</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-duplicate-add-flag/m-p/337599#M76690</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; t;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;input&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; ID$;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;cards&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;a010&lt;/P&gt;
&lt;P&gt;a010&lt;/P&gt;
&lt;P&gt;a010&lt;/P&gt;
&lt;P&gt;a011&lt;/P&gt;
&lt;P&gt;a012&lt;/P&gt;
&lt;P&gt;a012&lt;/P&gt;
&lt;P&gt;a013&lt;/P&gt;
&lt;P&gt;a013&lt;/P&gt;
&lt;P&gt;a013&lt;/P&gt;
&lt;P&gt;a013&lt;/P&gt;
&lt;P&gt;a014&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New"&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New"&gt;sql&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;create&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New"&gt;table&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; t2 &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;as&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;select&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; *&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;, case &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;when&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ID &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;in&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;(&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;select&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New"&gt;distinct&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; ID &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;from&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; t &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;group&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New"&gt;by&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; ID having count(ID)&amp;gt;&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New"&gt;) &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;then&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New"&gt;else&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New"&gt;0&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New"&gt; end &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;as&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; Dummy_Var&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;from&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; t;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New"&gt;&lt;STRONG&gt;quit&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Mar 2017 21:19:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-duplicate-add-flag/m-p/337599#M76690</guid>
      <dc:creator>jhlaramore</dc:creator>
      <dc:date>2017-03-02T21:19:45Z</dc:date>
    </item>
  </channel>
</rss>

