<?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, check if var1 has content, if no then flag in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/if-duplicate-check-if-var1-has-content-if-no-then-flag/m-p/337911#M76817</link>
    <description>&lt;P&gt;hi nehalsanghvi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if there are multiple rows for any ID, but not all rows have a value in Var1 (some do), then what would you want the new_dummy_var to be?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The new_dummy_var&amp;nbsp;to be set to 1 only if there are no values in Var1 at all. Thanks,&lt;/P&gt;</description>
    <pubDate>Fri, 03 Mar 2017 17:09:20 GMT</pubDate>
    <dc:creator>brulard</dc:creator>
    <dc:date>2017-03-03T17:09:20Z</dc:date>
    <item>
      <title>if duplicate, check if var1 has content, if no then flag</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-duplicate-check-if-var1-has-content-if-no-then-flag/m-p/337602#M76691</link>
      <description>&lt;P&gt;hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;can someone recommend some code so that sas check for condition: if value IDs is duplicate [could be more than 1 duplicate], then scan Var1 for content, if no content, create new_dummy_var=1. If value IDs not duplicate, skip.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Var1 is numeric.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;UPDATING Example outcome:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;IDs &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Var 1 &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;SPAN&gt;new_dummy_var&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;A001 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;5&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;A001 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;6&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;A001 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;A002 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;A002 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;A003&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 5&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;A003&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;A004&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;**Update: In the example outcome, note that&amp;nbsp;because&amp;nbsp;one of the duplicate observation&amp;nbsp;A003 has a 5 in Var1, the program should move on, and not assign a value in New_dummy_var.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;**New_dummy_var is only meant to be a flag, so not care if char or numeric.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thank you very much&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Dave&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Mar 2017 12:28:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-duplicate-check-if-var1-has-content-if-no-then-flag/m-p/337602#M76691</guid>
      <dc:creator>brulard</dc:creator>
      <dc:date>2017-03-03T12:28:39Z</dc:date>
    </item>
    <item>
      <title>Re: if duplicate, check if var1 has content, if no then flag</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-duplicate-check-if-var1-has-content-if-no-then-flag/m-p/337606#M76692</link>
      <description>&lt;P&gt;Expand on the previous solution &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/64767"&gt;@brulard&lt;/a&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data t;
input ID$ Var1$;
cards;
a001 A
a001 A
a001 A
a002 .
a002 .
a003 .
a004 .
;
run;

data t2;
set t;
by id;
new_dummy_var= ^(first.ID and last.ID) and var1='';
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Edit: I created Var1 as a character variable, but if yours is numeric,&amp;nbsp;this statement would work:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;new_dummy_var= ^(first.ID and last.ID) and var1=.;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The missing(var1) function that Art297 used below&amp;nbsp;works with either character or numeric data type.&lt;/P&gt;</description>
      <pubDate>Thu, 02 Mar 2017 22:14:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-duplicate-check-if-var1-has-content-if-no-then-flag/m-p/337606#M76692</guid>
      <dc:creator>nehalsanghvi</dc:creator>
      <dc:date>2017-03-02T22:14:04Z</dc:date>
    </item>
    <item>
      <title>Re: if duplicate, check if var1 has content, if no then flag</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-duplicate-check-if-var1-has-content-if-no-then-flag/m-p/337609#M76694</link>
      <description>&lt;PRE&gt;data want;
  set have;
  by ID;
  if not(first.id and last.id) then do;
    if missing(Var1) then new_dummy_var=1;
  end;
run;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;</description>
      <pubDate>Thu, 02 Mar 2017 21:31:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-duplicate-check-if-var1-has-content-if-no-then-flag/m-p/337609#M76694</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-03-02T21:31:53Z</dc:date>
    </item>
    <item>
      <title>Re: if duplicate, check if var1 has content, if no then flag</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-duplicate-check-if-var1-has-content-if-no-then-flag/m-p/337613#M76696</link>
      <description>&lt;P&gt;Just to clarify the question, what should the dummy variable be in this case?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;IDs &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Var 1 &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;SPAN&gt;new_dummy_var&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;A001&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;A001&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;A001 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 5&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Your answer makes a big difference in the complexity of the programming.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Mar 2017 21:39:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-duplicate-check-if-var1-has-content-if-no-then-flag/m-p/337613#M76696</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-03-02T21:39:44Z</dc:date>
    </item>
    <item>
      <title>Re: if duplicate, check if var1 has content, if no then flag</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-duplicate-check-if-var1-has-content-if-no-then-flag/m-p/337700#M76735</link>
      <description>&lt;P&gt;As Astounding said.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input IDs  $        Var    ;
cards;
A001           5 .
A001           6 .
A001           5    .
A002            .                
A002            .                
A003 . .
A004 . .
;
run;

proc sql;
select *,case when(count(*) ne 1 and sum(missing(var))=count(*)) then 1 else . end as dummy
 from have
  group by ids;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 03 Mar 2017 03:35:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-duplicate-check-if-var1-has-content-if-no-then-flag/m-p/337700#M76735</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-03-03T03:35:20Z</dc:date>
    </item>
    <item>
      <title>Re: if duplicate, check if var1 has content, if no then flag</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-duplicate-check-if-var1-has-content-if-no-then-flag/m-p/337798#M76779</link>
      <description>&lt;P&gt;It could be a number or char. thanks&lt;/P&gt;</description>
      <pubDate>Fri, 03 Mar 2017 12:34:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-duplicate-check-if-var1-has-content-if-no-then-flag/m-p/337798#M76779</guid>
      <dc:creator>brulard</dc:creator>
      <dc:date>2017-03-03T12:34:51Z</dc:date>
    </item>
    <item>
      <title>Re: if duplicate, check if var1 has content, if no then flag</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-duplicate-check-if-var1-has-content-if-no-then-flag/m-p/337821#M76784</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/64767"&gt;@brulard&lt;/a&gt;&amp;nbsp;the question is, if there are multiple rows for any ID, but not all rows have a value in Var1 (some do), then what would you want the new_dummy_var to be? Should new_dummy_var&amp;nbsp;be set to 1 only if there are &lt;EM&gt;no&lt;/EM&gt; values in Var1 at all? Or should it be set to 1 even if there are values in Var1 on some rows, but not on all rows?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Mar 2017 13:37:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-duplicate-check-if-var1-has-content-if-no-then-flag/m-p/337821#M76784</guid>
      <dc:creator>nehalsanghvi</dc:creator>
      <dc:date>2017-03-03T13:37:59Z</dc:date>
    </item>
    <item>
      <title>Re: if duplicate, check if var1 has content, if no then flag</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-duplicate-check-if-var1-has-content-if-no-then-flag/m-p/337835#M76789</link>
      <description>&lt;P&gt;This can also be done in a data step:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data want (drop=_:);
  do until (last.IDs);
    set have;
    by IDs;
    if first.IDs then do;
      _Vars=0;
      _Recs=0;
    end;
    _Recs+1;
    if not missing(var) then _Vars+1;
  end;
  do until (last.IDs);
    set have;
    by IDs;
    if _Recs GT 1 and _Vars=0 then new_dummy_var=1;
    output;
  end;
run;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;</description>
      <pubDate>Fri, 03 Mar 2017 14:35:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-duplicate-check-if-var1-has-content-if-no-then-flag/m-p/337835#M76789</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-03-03T14:35:23Z</dc:date>
    </item>
    <item>
      <title>Re: if duplicate, check if var1 has content, if no then flag</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-duplicate-check-if-var1-has-content-if-no-then-flag/m-p/337911#M76817</link>
      <description>&lt;P&gt;hi nehalsanghvi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if there are multiple rows for any ID, but not all rows have a value in Var1 (some do), then what would you want the new_dummy_var to be?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The new_dummy_var&amp;nbsp;to be set to 1 only if there are no values in Var1 at all. Thanks,&lt;/P&gt;</description>
      <pubDate>Fri, 03 Mar 2017 17:09:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-duplicate-check-if-var1-has-content-if-no-then-flag/m-p/337911#M76817</guid>
      <dc:creator>brulard</dc:creator>
      <dc:date>2017-03-03T17:09:20Z</dc:date>
    </item>
  </channel>
</rss>

