<?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: Store max value in 1 file to use in other file in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Store-max-value-in-1-file-to-use-in-other-file/m-p/402011#M97585</link>
    <description>&lt;P&gt;This is amazing code with proc SQL!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 06 Oct 2017 23:38:48 GMT</pubDate>
    <dc:creator>hhchenfx</dc:creator>
    <dc:date>2017-10-06T23:38:48Z</dc:date>
    <item>
      <title>Store max value in 1 file to use in other file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Store-max-value-in-1-file-to-use-in-other-file/m-p/401985#M97578</link>
      <description>&lt;P&gt;Hello Everyone,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have 1 old project with project number&amp;nbsp; AND a new project without project &lt;SPAN&gt;number&amp;nbsp;&lt;/SPAN&gt;.&lt;/P&gt;
&lt;P&gt;As I have to assign new &lt;SPAN&gt;number&amp;nbsp;&lt;/SPAN&gt;to new project, I will take the last project &lt;SPAN&gt;number&amp;nbsp;&lt;/SPAN&gt;of old file and feed it to the new file and increase by 1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Look like in the new file, the code is simple like that:&lt;/P&gt;
&lt;P&gt;data new; set new;&lt;/P&gt;
&lt;P&gt;project_code= &amp;amp;Max_number + _N_;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In my example, the 2 new project should have number: 103, 104.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I dont know how get that &amp;amp;Max_number.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can anyone please help me?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;HHC&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data oldproject;
input  name :$5.  number;
datalines;
ab 1
cd 3
kk 102
;run;

data newproject;
input  name :$5. ;
datalines;
new1
new2
;run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Solution&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*take the last record and store the value to Maxnumber;
data last; set oldproject end=eof;
if eof then output;run;

proc sql noprint;
select number into: maxnumber
from last; quit;

data newproject; set newproject;
number = &amp;amp;maxnumber + _n_;
run;

*OR simply use the Max();

proc sql noprint;
   select max(number) into: maxnumber
   from oldproject;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 06 Oct 2017 23:40:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Store-max-value-in-1-file-to-use-in-other-file/m-p/401985#M97578</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2017-10-06T23:40:51Z</dc:date>
    </item>
    <item>
      <title>Re: Store max value in 1 file to use in other file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Store-max-value-in-1-file-to-use-in-other-file/m-p/401994#M97580</link>
      <description>&lt;P&gt;And what's the expected output?&lt;/P&gt;</description>
      <pubDate>Fri, 06 Oct 2017 22:36:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Store-max-value-in-1-file-to-use-in-other-file/m-p/401994#M97580</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-10-06T22:36:53Z</dc:date>
    </item>
    <item>
      <title>Re: Store max value in 1 file to use in other file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Store-max-value-in-1-file-to-use-in-other-file/m-p/402000#M97582</link>
      <description>&lt;P&gt;Something like this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc sql noprint;
   select max(number) into: maxnumber
   from oldproject;
quit;

data newproject;
input  name :$5. ;
number = &amp;amp;maxnumber + _n_;
datalines;
new1
new2
;run;



&lt;/PRE&gt;
&lt;P&gt;Of course if you want the LAST value not the largest value of number from Oldproject you'll need different code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 06 Oct 2017 22:50:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Store-max-value-in-1-file-to-use-in-other-file/m-p/402000#M97582</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-10-06T22:50:25Z</dc:date>
    </item>
    <item>
      <title>Re: Store max value in 1 file to use in other file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Store-max-value-in-1-file-to-use-in-other-file/m-p/402006#M97583</link>
      <description>&lt;P&gt;The DATA NEWPROJECT step can be modified to fetch the maximum NUMBER value from oldproject:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data oldproject;
input  name :$5.  number;
datalines;
ab 1
cd 3
kk 102
;run;

data newproject (drop=_:);  
  input  name :$5. ;
  if _n_=1 then do until (old_end);
    set oldproject (keep=number rename=(number=_old_number)) end=old_end;
    number=max(number,_old_number);
  end;
  number+1;
datalines;
new1
new2
;run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 06 Oct 2017 23:10:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Store-max-value-in-1-file-to-use-in-other-file/m-p/402006#M97583</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-10-06T23:10:01Z</dc:date>
    </item>
    <item>
      <title>Re: Store max value in 1 file to use in other file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Store-max-value-in-1-file-to-use-in-other-file/m-p/402011#M97585</link>
      <description>&lt;P&gt;This is amazing code with proc SQL!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 06 Oct 2017 23:38:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Store-max-value-in-1-file-to-use-in-other-file/m-p/402011#M97585</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2017-10-06T23:38:48Z</dc:date>
    </item>
  </channel>
</rss>

