<?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: How to identify if values are same in 2 different variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-identify-if-values-are-same-in-2-different-variables/m-p/776933#M247114</link>
    <description>&lt;P&gt;One way&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID DATE :date9. EVENT $;
format DATE date9.;
datalines;
101 20Apr2021 Headache
101 21Apr2021 Nausea
101 20Apr2021 Headache
102 01May2021 Vomiting
102 02May2021 Vomiting
103 01Aug2021 Fatigue
104 01Aug2021 Fatigue
;

data want(drop = c);
   if _N_ = 1 then do;
      dcl hash h();
      h.definekey("ID", "DATE", "EVENT");
      h.definedata("c");
      h.definedone();
      
      do until (z);
         set have end = z;
         if h.find() ne 0 then c = 1;
         else                  c + 1;
         h.replace();
      end;
   end;
   
   set have;
   
   if h.find() = 0 and c &amp;gt; 1 then flag = "Y";
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Obs  ID   DATE       EVENT     flag
1    101  20APR2021  Headache  Y
2    101  21APR2021  Nausea  
3    101  20APR2021  Headache  Y
4    102  01MAY2021  Vomiting  
5    102  02MAY2021  Vomiting  
6    103  01AUG2021  Fatigue  
7    104  01AUG2021  Fatigue  &lt;/PRE&gt;</description>
    <pubDate>Thu, 28 Oct 2021 10:31:50 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2021-10-28T10:31:50Z</dc:date>
    <item>
      <title>How to identify if values are same in 2 different variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-identify-if-values-are-same-in-2-different-variables/m-p/776922#M247112</link>
      <description>&lt;P&gt;Dear All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset as below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;ID&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;DATE&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; EVENT&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;101&amp;nbsp; &amp;nbsp; 20Apr2021&amp;nbsp; &amp;nbsp; &amp;nbsp;Headache&lt;/P&gt;&lt;P&gt;101&amp;nbsp; &amp;nbsp; 21Apr2021&amp;nbsp; &amp;nbsp; &amp;nbsp;Nausea&lt;/P&gt;&lt;P&gt;101&amp;nbsp; &amp;nbsp; 20Apr2021&amp;nbsp; &amp;nbsp; &amp;nbsp;Headache&lt;/P&gt;&lt;P&gt;102&amp;nbsp; &amp;nbsp; 01May2021&amp;nbsp; &amp;nbsp; Vomiting&lt;/P&gt;&lt;P&gt;102&amp;nbsp; &amp;nbsp; 02May2021&amp;nbsp; &amp;nbsp; Vomiting&lt;/P&gt;&lt;P&gt;103&amp;nbsp; &amp;nbsp; 01Aug2021&amp;nbsp; &amp;nbsp; Fatigue&lt;/P&gt;&lt;P&gt;104&amp;nbsp; &amp;nbsp; 01Aug2021&amp;nbsp; &amp;nbsp; Fatigue&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to flag the records where the observations in date and event column are same per each ID.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The output should be like the below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;ID&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;DATE&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; EVENT&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;FLAG&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;101&amp;nbsp; &amp;nbsp; 20Apr2021&amp;nbsp; &amp;nbsp; &amp;nbsp;Headache&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Y&lt;/P&gt;&lt;P&gt;101&amp;nbsp; &amp;nbsp; 21Apr2021&amp;nbsp; &amp;nbsp; &amp;nbsp;Nausea&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;101&amp;nbsp; &amp;nbsp; 20Apr2021&amp;nbsp; &amp;nbsp; &amp;nbsp;Headache&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Y&lt;/P&gt;&lt;P&gt;102&amp;nbsp; &amp;nbsp; 01May2021&amp;nbsp; &amp;nbsp; Vomiting&lt;/P&gt;&lt;P&gt;102&amp;nbsp; &amp;nbsp; 02May2021&amp;nbsp; &amp;nbsp; Vomiting&lt;/P&gt;&lt;P&gt;103&amp;nbsp; &amp;nbsp; 01Aug2021&amp;nbsp; &amp;nbsp; Fatigue&lt;/P&gt;&lt;P&gt;104&amp;nbsp; &amp;nbsp; 01Aug2021&amp;nbsp; &amp;nbsp; Fatigue&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please help&lt;/P&gt;</description>
      <pubDate>Thu, 28 Oct 2021 09:43:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-identify-if-values-are-same-in-2-different-variables/m-p/776922#M247112</guid>
      <dc:creator>r3570</dc:creator>
      <dc:date>2021-10-28T09:43:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to identify if values are same in 2 different variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-identify-if-values-are-same-in-2-different-variables/m-p/776933#M247114</link>
      <description>&lt;P&gt;One way&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID DATE :date9. EVENT $;
format DATE date9.;
datalines;
101 20Apr2021 Headache
101 21Apr2021 Nausea
101 20Apr2021 Headache
102 01May2021 Vomiting
102 02May2021 Vomiting
103 01Aug2021 Fatigue
104 01Aug2021 Fatigue
;

data want(drop = c);
   if _N_ = 1 then do;
      dcl hash h();
      h.definekey("ID", "DATE", "EVENT");
      h.definedata("c");
      h.definedone();
      
      do until (z);
         set have end = z;
         if h.find() ne 0 then c = 1;
         else                  c + 1;
         h.replace();
      end;
   end;
   
   set have;
   
   if h.find() = 0 and c &amp;gt; 1 then flag = "Y";
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Obs  ID   DATE       EVENT     flag
1    101  20APR2021  Headache  Y
2    101  21APR2021  Nausea  
3    101  20APR2021  Headache  Y
4    102  01MAY2021  Vomiting  
5    102  02MAY2021  Vomiting  
6    103  01AUG2021  Fatigue  
7    104  01AUG2021  Fatigue  &lt;/PRE&gt;</description>
      <pubDate>Thu, 28 Oct 2021 10:31:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-identify-if-values-are-same-in-2-different-variables/m-p/776933#M247114</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2021-10-28T10:31:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to identify if values are same in 2 different variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-identify-if-values-are-same-in-2-different-variables/m-p/776935#M247116</link>
      <description>&lt;P&gt;This looks somewhat complex program. Hard for me to understand. Could you please help me with a simple easy to understand program ?&lt;/P&gt;</description>
      <pubDate>Thu, 28 Oct 2021 10:55:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-identify-if-values-are-same-in-2-different-variables/m-p/776935#M247116</guid>
      <dc:creator>r3570</dc:creator>
      <dc:date>2021-10-28T10:55:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to identify if values are same in 2 different variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-identify-if-values-are-same-in-2-different-variables/m-p/777195#M247229</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/382012"&gt;@r3570&lt;/a&gt;,&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/382012"&gt;@r3570&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;This looks somewhat complex program. Hard for me to understand. Could you please help me with a simple easy to understand program ?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Maybe it's easier to understand if you split the task into several short steps:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Create a temporary unique sort key _SEQNO */

data _tmp / view=_tmp;
set have;
_seqno=_n_;
run;

/* Separate duplicate and unique ID-DATE-EVENT combinations */

proc sort data=_tmp out=dup nouniquekey uniqueout=uni;
by id date event;
run;

proc sort data=dup; by _seqno; run;
proc sort data=uni; by _seqno; run;

/* Reunite the two parts, flagging the duplicates */

data want(drop=_seqno);
set dup(in=d) uni;
by _seqno;
if d then flag='Y';
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 29 Oct 2021 09:00:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-identify-if-values-are-same-in-2-different-variables/m-p/777195#M247229</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-10-29T09:00:34Z</dc:date>
    </item>
  </channel>
</rss>

