<?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 Flagging values with the same variable among IDs with more thab in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Flagging-values-with-the-same-variable-among-IDs-with-more-thab/m-p/875434#M345889</link>
    <description>&lt;P&gt;Hi there,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a really large dataset and I was wondering if there was a way I can flag whether a particular variable value is the same or not for IDs with more than 1 record. I am not looking for exact duplicates across all variable values (i.e can't use NODUPKEY), nor am I interested in removing the exact duplicates, I just wanted to flag whether the values were the same or not. I have included a same dataset below.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Fruit&amp;nbsp; &amp;nbsp; &amp;nbsp;Colour&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Flag&lt;/P&gt;&lt;P&gt;1001&amp;nbsp; &amp;nbsp;Apple&amp;nbsp; &amp;nbsp; Purple&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;1003&amp;nbsp; &amp;nbsp;Banana&amp;nbsp; Black&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;&lt;P&gt;1001&amp;nbsp; &amp;nbsp;Apple&amp;nbsp; &amp;nbsp; &amp;nbsp; Purple&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;1005&amp;nbsp; &amp;nbsp;Mango&amp;nbsp; &amp;nbsp;Blue&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;&lt;P&gt;1005&amp;nbsp; &amp;nbsp;Mango&amp;nbsp; &amp;nbsp; Pink&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/P&gt;&lt;P&gt;1002&amp;nbsp; &amp;nbsp;Apple&amp;nbsp; &amp;nbsp; &amp;nbsp;Red&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;&lt;P&gt;1006&amp;nbsp; &amp;nbsp;Cherry&amp;nbsp; &amp;nbsp;Yellow&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/P&gt;&lt;P&gt;1001&amp;nbsp; &amp;nbsp;Pear&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Purple&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For the above dataset, among IDs with more than 1 record, I am interested in flagging whether the fruit variable value is the same/different among all observations for that particular ID. I have included how I would like my flag variable to code. For example ID 1001, the fruit variable is the same only for 2/3 observations, so I wanted to flag this as 1 (not the same).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you once again for taking the time to read through my question and I am looking forward to reading any suggestions you might have to solve my problem!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 12 May 2023 11:42:20 GMT</pubDate>
    <dc:creator>jnivi</dc:creator>
    <dc:date>2023-05-12T11:42:20Z</dc:date>
    <item>
      <title>Flagging values with the same variable among IDs with more thab</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flagging-values-with-the-same-variable-among-IDs-with-more-thab/m-p/875434#M345889</link>
      <description>&lt;P&gt;Hi there,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a really large dataset and I was wondering if there was a way I can flag whether a particular variable value is the same or not for IDs with more than 1 record. I am not looking for exact duplicates across all variable values (i.e can't use NODUPKEY), nor am I interested in removing the exact duplicates, I just wanted to flag whether the values were the same or not. I have included a same dataset below.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Fruit&amp;nbsp; &amp;nbsp; &amp;nbsp;Colour&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Flag&lt;/P&gt;&lt;P&gt;1001&amp;nbsp; &amp;nbsp;Apple&amp;nbsp; &amp;nbsp; Purple&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;1003&amp;nbsp; &amp;nbsp;Banana&amp;nbsp; Black&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;&lt;P&gt;1001&amp;nbsp; &amp;nbsp;Apple&amp;nbsp; &amp;nbsp; &amp;nbsp; Purple&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;1005&amp;nbsp; &amp;nbsp;Mango&amp;nbsp; &amp;nbsp;Blue&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;&lt;P&gt;1005&amp;nbsp; &amp;nbsp;Mango&amp;nbsp; &amp;nbsp; Pink&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/P&gt;&lt;P&gt;1002&amp;nbsp; &amp;nbsp;Apple&amp;nbsp; &amp;nbsp; &amp;nbsp;Red&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;&lt;P&gt;1006&amp;nbsp; &amp;nbsp;Cherry&amp;nbsp; &amp;nbsp;Yellow&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/P&gt;&lt;P&gt;1001&amp;nbsp; &amp;nbsp;Pear&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Purple&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For the above dataset, among IDs with more than 1 record, I am interested in flagging whether the fruit variable value is the same/different among all observations for that particular ID. I have included how I would like my flag variable to code. For example ID 1001, the fruit variable is the same only for 2/3 observations, so I wanted to flag this as 1 (not the same).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you once again for taking the time to read through my question and I am looking forward to reading any suggestions you might have to solve my problem!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 May 2023 11:42:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flagging-values-with-the-same-variable-among-IDs-with-more-thab/m-p/875434#M345889</guid>
      <dc:creator>jnivi</dc:creator>
      <dc:date>2023-05-12T11:42:20Z</dc:date>
    </item>
    <item>
      <title>Re: Flagging values with the same variable among IDs with more thab</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flagging-values-with-the-same-variable-among-IDs-with-more-thab/m-p/875445#M345893</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data name;
infile cards expandtabs;
input icustomerid debt_code rep_code dr_inits $ dr_name $;
datalines ;
48196 367762168 131 Tami Baker
48196 337656029 131 Tami Baker
48196 302678693 131 Tami Baker
48197 302678693 131 Tami Baker
48197 302678693 131 Tami Bak
;
run;

proc sql;
create table want as
select *,count(distinct dr_name) ne 1 as flag
 from name
  group by icustomerid ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 12 May 2023 12:19:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flagging-values-with-the-same-variable-among-IDs-with-more-thab/m-p/875445#M345893</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2023-05-12T12:19:24Z</dc:date>
    </item>
    <item>
      <title>Re: Flagging values with the same variable among IDs with more thab</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flagging-values-with-the-same-variable-among-IDs-with-more-thab/m-p/875469#M345907</link>
      <description>&lt;P&gt;Alternative option with hash tables:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID       Fruit : $     Colour : $;
cards;
1001   Apple    Purple          1
1003   Banana  Black          0
1001   Apple      Purple        1
1005   Mango   Blue            0
1005   Mango    Pink           0
1002   Apple     Red            0
1006   Cherry   Yellow         0
1001   Pear       Purple        1
;
run;
proc print;
run;

data want;

  length F $ 8 ; drop F;
  declare hash H();
  H.defineKey("ID");
  H.defineData("F","Flag");
  H.defineDone();


  do until(EOF1);
    set have end=EOF1;

    if 0=H.find() then do; if F NE Fruit then Flag+1; end;
    else Flag=-1;

    _N_=H.replace();
  end;


  do until(EOF2);
    set have end=EOF2;

    _N_=H.find();

    Flag=Flag&amp;gt;0;
    output;
  end;
stop;
run;
proc print;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Fri, 12 May 2023 13:52:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flagging-values-with-the-same-variable-among-IDs-with-more-thab/m-p/875469#M345907</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2023-05-12T13:52:50Z</dc:date>
    </item>
  </channel>
</rss>

