<?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: Find the last codes in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Find-the-last-codes/m-p/468558#M119696</link>
    <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;...&lt;/P&gt;&lt;P&gt;I learned new techniques from you...Never used in proc sort..always used as SQL into clause..&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Am still working on my query as i have to use two variables in join and sort it...i hope i will get it down soon...thanks for your help..&lt;/P&gt;&lt;P&gt;Cheers!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 08 Jun 2018 00:27:53 GMT</pubDate>
    <dc:creator>BaalaRaaji</dc:creator>
    <dc:date>2018-06-08T00:27:53Z</dc:date>
    <item>
      <title>Find the last codes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-the-last-codes/m-p/468265#M119581</link>
      <description>&lt;P&gt;Hi Guys,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have got below sample data set&amp;nbsp; which has codes for latest year(2002).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data inventory_LATEST;&lt;BR /&gt;input PartNumber $ Description $ InStock &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/153152"&gt;@17&lt;/a&gt;&lt;BR /&gt;ReceivedDate date9. @27 code $;&lt;BR /&gt;format ReceivedDate date9.;&lt;BR /&gt;datalines;&lt;BR /&gt;K89R seal 34 27jul2002 H1&lt;BR /&gt;M4J7 sander 98 20jun2002 H2&lt;BR /&gt;LK43 filter 121 19may2002 F1&lt;BR /&gt;MN21 brace 43 10aug2002 F2&lt;BR /&gt;BC85 clamp 80 16aug2002 G&lt;BR /&gt;NCF3 valve 198 20mar2002 G1&lt;BR /&gt;KJ66 cutter 6 18jun2002 G2&lt;BR /&gt;UYN7 rod 211 09sep2002 G3&lt;BR /&gt;JD03 switch 383 09jan2002 H1&lt;BR /&gt;BV1E timer 26 03aug2002 H2&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And the other dataset has 3 years of smilar find with different codes..&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data inventoryhist;&lt;BR /&gt;input PartNumber $ Description $ InStock &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/153152"&gt;@17&lt;/a&gt;&lt;BR /&gt;ReceivedDate date9. @27 code $;&lt;BR /&gt;format ReceivedDate date9.;&lt;BR /&gt;datalines;&lt;BR /&gt;K89R seal 34 27jul1999 T&lt;BR /&gt;K89R seal 34 27jul1998 H1&lt;BR /&gt;K89R seal 34 27jul1997 G&lt;BR /&gt;M4J7 sander 98 20jun1999 L&lt;BR /&gt;M4J7 sander 98 20jun1998 H2&lt;BR /&gt;M4J7 sander 98 20jun1997 H2&lt;BR /&gt;LK43 filter 121 19may2000 M&lt;BR /&gt;LK43 filter 121 19may1998 F1&lt;BR /&gt;LK43 filter 121 19may1997 T&lt;BR /&gt;MN21 brace 43 10aug2000 F2&lt;BR /&gt;MN21 brace 43 10aug1998 F2&lt;BR /&gt;MN21 brace 43 10aug1997 F2&lt;BR /&gt;BC85 clamp 80 16aug2000 K&lt;BR /&gt;BC85 clamp 80 16aug1998 G&lt;BR /&gt;BC85 clamp 80 16aug1997 L&lt;BR /&gt;NCF3 valve 198 20mar2000 G1&lt;BR /&gt;NCF3 valve 198 20mar1998 G1&lt;BR /&gt;NCF3 valve 198 20mar1997 K&lt;BR /&gt;KJ66 cutter 6 18jun2000 J&lt;BR /&gt;UYN7 rod 211 09sep1998 G3&lt;BR /&gt;UYN7 rod 211 09sep1999 H&lt;BR /&gt;UYN7 rod 211 09sep2000 H&lt;BR /&gt;JD03 switch 383 09jan2001 L&lt;BR /&gt;JD03 switch 383 09jan1998 H1&lt;BR /&gt;JD03 switch 383 09jan1999 H1&lt;BR /&gt;BV1E timer 26 03aug2001 M&lt;BR /&gt;BV1E timer 26 03aug1998 H2&lt;BR /&gt;BV1E timer 26 03aug1999 H1&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i want to write a code that pick the last codes(which are different to latest(2002).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;output shouls be like below,,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PartNumber Description InStock ReceivedDate code prevcode&lt;BR /&gt;K89R seal 34 27jul2002 H1 T&lt;BR /&gt;M4J7 sander 98 20jun2002 H2 L&lt;BR /&gt;LK43 filter 121 19may2002 F1 M&lt;BR /&gt;MN21 brace 43 10aug2002 F2 F2&lt;BR /&gt;BC85 clamp 80 16aug2002 G K&lt;BR /&gt;NCF3 valve 198 20mar2002 G1 G1&lt;BR /&gt;KJ66 cutter 6 18jun2002 G2 J&lt;BR /&gt;UYN7 rod 211 09sep2002 G3 H&lt;BR /&gt;JD03 switch 383 09jan2002 H1 L&lt;BR /&gt;BV1E timer 26 03aug2002 H2 M&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help much appreciated...i have explained one senario for one record.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(first dataset)&lt;/P&gt;&lt;P&gt;K89R seal&amp;nbsp; &amp;nbsp;34&amp;nbsp; 27jul2002 H1&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(second dataset)&lt;/P&gt;&lt;P&gt;K89R seal 34 27jul1999 T&lt;BR /&gt;K89R seal 34 27jul1998 H1&lt;BR /&gt;K89R seal 34 27jul1997 G&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Final dataset(latest to pick is for this record after 2002-1999) so on&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;K89R seal&amp;nbsp; &amp;nbsp;34&amp;nbsp; 27jul2002 H1&amp;nbsp; T&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;please let me know if you have questions.thanks&lt;/P&gt;</description>
      <pubDate>Thu, 07 Jun 2018 07:14:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-the-last-codes/m-p/468265#M119581</guid>
      <dc:creator>BaalaRaaji</dc:creator>
      <dc:date>2018-06-07T07:14:49Z</dc:date>
    </item>
    <item>
      <title>Re: Find the last codes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-the-last-codes/m-p/468272#M119584</link>
      <description>&lt;P&gt;Try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data inventory_LATEST;
input
  PartNumber $
  Description $
  InStock
  ReceivedDate :date9.
  code $
;
format ReceivedDate date9.;
seq = _n_;
datalines;
K89R seal 34 27jul2002 H1
M4J7 sander 98 20jun2002 H2
LK43 filter 121 19may2002 F1
MN21 brace 43 10aug2002 F2
BC85 clamp 80 16aug2002 G
NCF3 valve 198 20mar2002 G1
KJ66 cutter 6 18jun2002 G2
UYN7 rod 211 09sep2002 G3
JD03 switch 383 09jan2002 H1
BV1E timer 26 03aug2002 H2
;
run;

data inventoryhist;
input
  PartNumber $
  Description $
  InStock
  ReceivedDate :date9.
  code $
;
format ReceivedDate date9.;
datalines;
K89R seal 34 27jul1999 T
K89R seal 34 27jul1998 H1
K89R seal 34 27jul1997 G
M4J7 sander 98 20jun1999 L
M4J7 sander 98 20jun1998 H2
M4J7 sander 98 20jun1997 H2
LK43 filter 121 19may2000 M
LK43 filter 121 19may1998 F1
LK43 filter 121 19may1997 T
MN21 brace 43 10aug2000 F2
MN21 brace 43 10aug1998 F2
MN21 brace 43 10aug1997 F2
BC85 clamp 80 16aug2000 K
BC85 clamp 80 16aug1998 G
BC85 clamp 80 16aug1997 L
NCF3 valve 198 20mar2000 G1
NCF3 valve 198 20mar1998 G1
NCF3 valve 198 20mar1997 K
KJ66 cutter 6 18jun2000 J
UYN7 rod 211 09sep1998 G3
UYN7 rod 211 09sep1999 H
UYN7 rod 211 09sep2000 H
JD03 switch 383 09jan2001 L
JD03 switch 383 09jan1998 H1
JD03 switch 383 09jan1999 H1
BV1E timer 26 03aug2001 M
BV1E timer 26 03aug1998 H2
BV1E timer 26 03aug1999 H1
;
run;

proc sort data=inventory_latest;
by partnumber;
run;


proc sort data=inventoryhist;
by partnumber descending receiveddate;
run;

data want;
merge
  inventory_latest (in=a)
  inventoryhist (
    in=b
    keep=partnumber code
    rename=(code=prevcode)
  )
;
by partnumber;
if a;
if first.partnumber;
run;

proc sort data=want;
by seq;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that I had to modify the input statements to correctly work.&lt;/P&gt;</description>
      <pubDate>Thu, 07 Jun 2018 07:37:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-the-last-codes/m-p/468272#M119584</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-06-07T07:37:32Z</dc:date>
    </item>
    <item>
      <title>Re: Find the last codes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-the-last-codes/m-p/468294#M119589</link>
      <description>KurtBremser you are Genius....I need more help on this query...&lt;BR /&gt;&lt;BR /&gt;The first part code has 1700records with codes as F,G,H...as on 31MAR2018&lt;BR /&gt;&lt;BR /&gt;I have to find for these records in historic table which has data since 2011..that has codes other than F,G,H..comparing our previous file...&lt;BR /&gt;It has some billion records...(historic one)&lt;BR /&gt;&lt;BR /&gt;Can you advice how to write a code..?&lt;BR /&gt;&lt;BR /&gt;Appreciate your help...thank you...</description>
      <pubDate>Thu, 07 Jun 2018 08:17:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-the-last-codes/m-p/468294#M119589</guid>
      <dc:creator>BaalaRaaji</dc:creator>
      <dc:date>2018-06-07T08:17:05Z</dc:date>
    </item>
    <item>
      <title>Re: Find the last codes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-the-last-codes/m-p/468298#M119591</link>
      <description>&lt;P&gt;If the structure is as you showed, the code will scale, it's just a matter of time.&lt;/P&gt;
&lt;P&gt;If it's only 1700 partnumbers, those will easily fit into memory, so I'd start with&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
set inventory_latest (keep=partnumber) end=eof;
length numbers $32767;
retain numbers;
numbers = catx(',',numbers,quote(strip(partnumber)));
if eof then call symputx('partnumbers',numbers);
run;

proc sort
  data=inventoryhist (
    where=(partnumber in (&amp;amp;partnumbers))
  )
  out=temphist
;
by partnumber descending receiveddate;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;to reduce the history table to the necessary minimum.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Jun 2018 08:33:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-the-last-codes/m-p/468298#M119591</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-06-07T08:33:15Z</dc:date>
    </item>
    <item>
      <title>Re: Find the last codes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-the-last-codes/m-p/468327#M119601</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;I haven't seen that method for value-concatenation since&amp;nbsp; &amp;nbsp;&lt;FONT face="courier new,courier"&gt;SQL into&amp;nbsp;&lt;/FONT&gt; &amp;nbsp;appeared. Old habits die hard! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;I&amp;nbsp;stick to &amp;nbsp;&lt;FONT face="courier new,courier"&gt;into&lt;/FONT&gt;&amp;nbsp; not only for the compact code, but also because it allows 64 kB worth of values rather than 32kB; unless there are so many values that several lists&amp;nbsp;are necessary.&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Jun 2018 11:22:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-the-last-codes/m-p/468327#M119601</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2018-06-07T11:22:39Z</dc:date>
    </item>
    <item>
      <title>Re: Find the last codes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-the-last-codes/m-p/468558#M119696</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;...&lt;/P&gt;&lt;P&gt;I learned new techniques from you...Never used in proc sort..always used as SQL into clause..&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Am still working on my query as i have to use two variables in join and sort it...i hope i will get it down soon...thanks for your help..&lt;/P&gt;&lt;P&gt;Cheers!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jun 2018 00:27:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-the-last-codes/m-p/468558#M119696</guid>
      <dc:creator>BaalaRaaji</dc:creator>
      <dc:date>2018-06-08T00:27:53Z</dc:date>
    </item>
  </channel>
</rss>

