<?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 compare two variables across observations? in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/How-to-compare-two-variables-across-observations/m-p/687731#M24561</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Some points to consider to help get a solution are:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What are the rules / logic for deciding what value should be in the group_&lt;SPAN style="font-family: inherit;"&gt;new&lt;/SPAN&gt;&lt;SPAN style="font-family: inherit;"&gt;&amp;nbsp;variable?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;At the moment the example in the question shows it is always "A".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Should it always be "A" or can it ever change? If it can change then under what circumstances and what should the different value be?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I recommend you edit the original question to further clarify.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Amir.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edited to add recommendation.&lt;/P&gt;</description>
    <pubDate>Wed, 30 Sep 2020 06:43:22 GMT</pubDate>
    <dc:creator>Amir</dc:creator>
    <dc:date>2020-09-30T06:43:22Z</dc:date>
    <item>
      <title>How to compare two variables across observations?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-compare-two-variables-across-observations/m-p/687728#M24560</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have a Data Set looking like this:&lt;/P&gt;&lt;P&gt;id&amp;nbsp; group&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp;A&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp;B&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp;A&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp;B&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and want to have something like this:&lt;/P&gt;&lt;P&gt;id&amp;nbsp; &amp;nbsp;group&amp;nbsp; &amp;nbsp;group_new&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; A&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; B&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; A&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; A&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; B&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; A&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Unfortunately, id's belonging to one group are not consecutive observations.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 06:10:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-compare-two-variables-across-observations/m-p/687728#M24560</guid>
      <dc:creator>newfee</dc:creator>
      <dc:date>2020-09-30T06:10:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare two variables across observations?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-compare-two-variables-across-observations/m-p/687731#M24561</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Some points to consider to help get a solution are:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What are the rules / logic for deciding what value should be in the group_&lt;SPAN style="font-family: inherit;"&gt;new&lt;/SPAN&gt;&lt;SPAN style="font-family: inherit;"&gt;&amp;nbsp;variable?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;At the moment the example in the question shows it is always "A".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Should it always be "A" or can it ever change? If it can change then under what circumstances and what should the different value be?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I recommend you edit the original question to further clarify.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Amir.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edited to add recommendation.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 06:43:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-compare-two-variables-across-observations/m-p/687731#M24561</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2020-09-30T06:43:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare two variables across observations?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-compare-two-variables-across-observations/m-p/687746#M24562</link>
      <description>&lt;P&gt;I tried to simplify the data. The "have"-table actually looks more like this:&lt;/P&gt;&lt;P&gt;id&amp;nbsp; &amp;nbsp;group&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; A&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; B&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; A&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; C&lt;/P&gt;&lt;P&gt;4&amp;nbsp; &amp;nbsp; &amp;nbsp; C&lt;/P&gt;&lt;P&gt;5&amp;nbsp; &amp;nbsp; &amp;nbsp; D&lt;/P&gt;&lt;P&gt;6&amp;nbsp; &amp;nbsp; &amp;nbsp; E&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;7&amp;nbsp; &amp;nbsp; &amp;nbsp; B&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and what I want is:&lt;/P&gt;&lt;P&gt;id&amp;nbsp; &amp;nbsp; group&amp;nbsp; &amp;nbsp; group_new&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;A&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; B&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;A&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;A&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; C&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; C&lt;/P&gt;&lt;P&gt;4&amp;nbsp; &amp;nbsp; &amp;nbsp; C&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; C&lt;/P&gt;&lt;P&gt;5&amp;nbsp; &amp;nbsp; &amp;nbsp; D&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; D&lt;/P&gt;&lt;P&gt;6&amp;nbsp; &amp;nbsp; &amp;nbsp; E&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; E&lt;/P&gt;&lt;P&gt;7&amp;nbsp; &amp;nbsp; &amp;nbsp; B&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; A&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The general rule is that the same id can have only one group, not two (in "have" it is never more than two). So id 2 must either have group A or group B (id 1 and 2 both have group A, id 2 and 7 are in group B, so id 2 is in group A and B and I want to "overwrite" B with A for id 2 and id 7).&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 08:52:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-compare-two-variables-across-observations/m-p/687746#M24562</guid>
      <dc:creator>newfee</dc:creator>
      <dc:date>2020-09-30T08:52:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare two variables across observations?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-compare-two-variables-across-observations/m-p/688199#M24583</link>
      <description>&lt;P&gt;Why overwrite B with A not A with B ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data have;
infile cards ;
input from $  to $ ;
cards;
1      A
2      B
2      A
3      C
4      C
5      D
6      E  
7      B
;
run;


data full;
  set have end=last;
  if _n_ eq 1 then do;
   declare hash h();
    h.definekey('node');
     h.definedata('node');
     h.definedone();
  end;
  output;
  node=from; h.replace();
  from=to; to=node;
  output;
  node=from; h.replace();
  if last then h.output(dataset:'node');
  drop node;
run;


data want(keep=node household);
declare hash ha(ordered:'a');
declare hiter hi('ha');
ha.definekey('count');
ha.definedata('last');
ha.definedone();
declare hash _ha(hashexp: 20);
_ha.definekey('key');
_ha.definedone();

if 0 then set full;
declare hash from_to(dataset:'full(where=(from is not missing and to is not missing))',hashexp:20,multidata:'y');
 from_to.definekey('from');
 from_to.definedata('to');
 from_to.definedone();

if 0 then set node;
declare hash no(dataset:'node');
declare hiter hi_no('no');
 no.definekey('node');
 no.definedata('node');
 no.definedone();
 

do while(hi_no.next()=0);
 household+1; output;
 count=1;
 key=node;_ha.add();
 last=node;ha.add();
 rc=hi.first();
 do while(rc=0);
   from=last;rx=from_to.find();
   do while(rx=0);
     key=to;ry=_ha.check();
      if ry ne 0 then do;
       node=to;output;rr=no.remove(key:node);
       key=to;_ha.add();
       count+1;
       last=to;ha.add();
      end;
      rx=from_to.find_next();
   end;
   rc=hi.next();
end;
ha.clear();_ha.clear();
end;
stop;
run;

data want;
 set want;
 by household;
 length new_group $ 80;
 retain new_group;
 if first.household then new_group=node;
run;

data final_want;
 if _n_=1 then do;
   if 0 then set want;
   declare hash h(dataset:'want');
   h.definekey('node');
   h.definedata('new_group');
   h.definedone();
 end;
set have;
h.find(key:from);
drop node household;
run;&lt;/PRE&gt;</description>
      <pubDate>Thu, 01 Oct 2020 14:01:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-compare-two-variables-across-observations/m-p/688199#M24583</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2020-10-01T14:01:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare two variables across observations?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-compare-two-variables-across-observations/m-p/689868#M24697</link>
      <description>Thank you so much!</description>
      <pubDate>Thu, 08 Oct 2020 05:06:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-compare-two-variables-across-observations/m-p/689868#M24697</guid>
      <dc:creator>newfee</dc:creator>
      <dc:date>2020-10-08T05:06:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare two variables across observations?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-compare-two-variables-across-observations/m-p/689869#M24698</link>
      <description>A could be overwritten with B, too. It doesn't matter. I just need A and B to be the same new_group.</description>
      <pubDate>Thu, 08 Oct 2020 05:10:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-compare-two-variables-across-observations/m-p/689869#M24698</guid>
      <dc:creator>newfee</dc:creator>
      <dc:date>2020-10-08T05:10:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare two variables across observations?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-compare-two-variables-across-observations/m-p/689931#M24704</link>
      <description>&lt;P&gt;If you have SAS/OR could try this code proposed by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/462"&gt;@PGStats&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;/* Same code as SAS/OR */
proc optnet data_links=have out_nodes=want GRAPH_DIRECTION=UNDIRECTED;
data_links_var from=from to=to;
concomp;
run;&lt;/PRE&gt;</description>
      <pubDate>Thu, 08 Oct 2020 11:23:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-compare-two-variables-across-observations/m-p/689931#M24704</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2020-10-08T11:23:25Z</dc:date>
    </item>
  </channel>
</rss>

