<?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 Question about consecutive variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Question-about-consecutive-variables/m-p/232830#M268125</link>
    <description>&lt;P&gt;I am looking for a way to compare multiple observations and output a file that contains the final number from multiple part number change observations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The data haveSorted below i have ordered only for ease of seeing how the part numbers are stored.&amp;nbsp; The actual data I have is not sorted in any way.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any recommendations would be greatly appreciated as I have been unable to think of a method to do this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA haveSorted;/*Manually sorted for ease of understanding*/
infile datalines delimiter=",";
input prev_part $ part_sup $;
datalines;
.,X1
X1,P2
P2,P5
P5,D3
.,4C3
4C3,7S2
7S2,6BW
.,5S2
.,6R1
6R1,3F3
3F3,24X
;


DATA have;
infile datalines delimiter=",";
input prev_part $ part_sup $;
datalines;
.,X1
X1,P2
3F3,24X
P2,P5
4C3,7S2
P5,D3
.,4C3
7S2,6BW
.,5S2
.,6R1
6R1,3F3
;


data want;
infile datalines delimiter=",";
input prev_part $ part_sup $ final_part $;
datalines;
.,X1,D3
X1,P2,D3
P2,P5,D3
P5,D3,D3
.,4C3,6BW
4C3,7S2,6BW
7S2,6BW,6BW
.,5S2,5S2
.,6R1,24X
6R1,3F3,24X
3F3,24X,24X
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 03 Nov 2015 00:52:04 GMT</pubDate>
    <dc:creator>dsbihill</dc:creator>
    <dc:date>2015-11-03T00:52:04Z</dc:date>
    <item>
      <title>Question about consecutive variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Question-about-consecutive-variables/m-p/232830#M268125</link>
      <description>&lt;P&gt;I am looking for a way to compare multiple observations and output a file that contains the final number from multiple part number change observations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The data haveSorted below i have ordered only for ease of seeing how the part numbers are stored.&amp;nbsp; The actual data I have is not sorted in any way.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any recommendations would be greatly appreciated as I have been unable to think of a method to do this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA haveSorted;/*Manually sorted for ease of understanding*/
infile datalines delimiter=",";
input prev_part $ part_sup $;
datalines;
.,X1
X1,P2
P2,P5
P5,D3
.,4C3
4C3,7S2
7S2,6BW
.,5S2
.,6R1
6R1,3F3
3F3,24X
;


DATA have;
infile datalines delimiter=",";
input prev_part $ part_sup $;
datalines;
.,X1
X1,P2
3F3,24X
P2,P5
4C3,7S2
P5,D3
.,4C3
7S2,6BW
.,5S2
.,6R1
6R1,3F3
;


data want;
infile datalines delimiter=",";
input prev_part $ part_sup $ final_part $;
datalines;
.,X1,D3
X1,P2,D3
P2,P5,D3
P5,D3,D3
.,4C3,6BW
4C3,7S2,6BW
7S2,6BW,6BW
.,5S2,5S2
.,6R1,24X
6R1,3F3,24X
3F3,24X,24X
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Nov 2015 00:52:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Question-about-consecutive-variables/m-p/232830#M268125</guid>
      <dc:creator>dsbihill</dc:creator>
      <dc:date>2015-11-03T00:52:04Z</dc:date>
    </item>
    <item>
      <title>Re: Question about consecutive variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Question-about-consecutive-variables/m-p/232845#M268126</link>
      <description>&lt;P&gt;Since you seem to have only one branch (vs. multiple branches like train station problem), Hash could work on your 'have' out of box.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;DATA have;
infile datalines delimiter=",";
input prev_part $ part_sup $;
datalines;
.,X1
X1,P2
3F3,24X
P2,P5
4C3,7S2
P5,D3
.,4C3
7S2,6BW
.,5S2
.,6R1
6R1,3F3
;


data want;
if _n_=1 then do;
dcl hash h(dataset:'have(rename=(prev_part=pre part_sup=final_part)', multidata&amp;amp;colon;'y');
h.definekey('pre');
h.definedata(all:'y');
h.definedone();
end;
set have;
length pre final_part $ 8;
rc=h.find(key: coalescec(prev_part, part_sup));
if rc ne 0 then final_part=part_sup;
else
do rc=0 by 0 while (rc=0);
rc=h.find(key:final_part);
end;
drop rc pre;
run;

&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Please note: for some reason, the forum macro messed up my code, it should be ... multidata&amp;amp;colon;'y');&lt;/P&gt;&lt;PRE&gt;&amp;nbsp;&lt;/PRE&gt;&lt;P&gt;..&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Nov 2015 02:41:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Question-about-consecutive-variables/m-p/232845#M268126</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2015-11-03T02:41:42Z</dc:date>
    </item>
    <item>
      <title>Re: Question about consecutive variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Question-about-consecutive-variables/m-p/232899#M268127</link>
      <description>You can also take a look at some of the procs under SAS/OR - possibly PROC BOM though I'm not sure.</description>
      <pubDate>Tue, 03 Nov 2015 15:28:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Question-about-consecutive-variables/m-p/232899#M268127</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2015-11-03T15:28:35Z</dc:date>
    </item>
  </channel>
</rss>

