<?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: To write a code that finds the max amount before the last amount in do until loop in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/To-write-a-code-that-finds-the-max-amount-before-the-last-amount/m-p/741071#M231631</link>
    <description>&lt;P&gt;Make the following change to the second part.&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;Instead of
if _n_=2 then flg=1;
use 
if _n_=2 then output;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;The want data set will have only one record. I am giving a sample code below&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data salary;
input salary year;
datalines;
200 1990
;
run;
data increaseit;
  set salary;
  do until (salary gt 1000);
    salary = salary + salary * 0.06;
    year = year + 1;
    if not(salary gt 1000) then output;
  end;
Run;
proc sort data=increaseit out=temp;
  by descending year;
run;
data want;
  set temp;
  by descending year;
  if _n_=2 then output;
run;&lt;BR /&gt;proc&amp;nbsp;print&amp;nbsp;data=want;&lt;BR /&gt;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The out put will&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="forum.PNG" style="width: 174px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/59309iA34CA39282053B96/image-size/large?v=v2&amp;amp;px=999" role="button" title="forum.PNG" alt="forum.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 13 May 2021 12:04:15 GMT</pubDate>
    <dc:creator>Sajid01</dc:creator>
    <dc:date>2021-05-13T12:04:15Z</dc:date>
    <item>
      <title>To write a code that finds the max amount before the last amount in do until loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/To-write-a-code-that-finds-the-max-amount-before-the-last-amount/m-p/740713#M231429</link>
      <description>&lt;P&gt;Hello team,&lt;/P&gt;
&lt;P&gt;I have a code and I want to write a code that finds the max amount before the last amount in do until loop? I can eye ball and say what it is. How can I do this by writing code?&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Blue Blue&lt;/P&gt;
&lt;PRE&gt;data salyr;  
input salary year;  
cards;  
134 2019  
run;

data increaseit;
set salyr;
do until (salary gt 1000);
salary = salary + salary * 0.06;
year = year + 1;
output;
end;
Run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 May 2021 04:02:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/To-write-a-code-that-finds-the-max-amount-before-the-last-amount/m-p/740713#M231429</guid>
      <dc:creator>GN0001</dc:creator>
      <dc:date>2021-05-12T04:02:54Z</dc:date>
    </item>
    <item>
      <title>Re: To write a code that finds the max amount before the last amount in do until loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/To-write-a-code-that-finds-the-max-amount-before-the-last-amount/m-p/740714#M231430</link>
      <description>&lt;P&gt;For example.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data increaseit;
  set salyr;
  do until (salary gt 1000);
    salary = salary + salary * 0.06;
    year = year + 1;
    if not(salary gt 1000) then output;
  end;
Run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 12 May 2021 04:16:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/To-write-a-code-that-finds-the-max-amount-before-the-last-amount/m-p/740714#M231430</guid>
      <dc:creator>japelin</dc:creator>
      <dc:date>2021-05-12T04:16:10Z</dc:date>
    </item>
    <item>
      <title>Re: To write a code that finds the max amount before the last amount in do until loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/To-write-a-code-that-finds-the-max-amount-before-the-last-amount/m-p/740765#M231457</link>
      <description>&lt;P&gt;&amp;nbsp;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/202329"&gt;@GN0001&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;Do you want the max value or the total sum?&lt;BR /&gt;Your code is creating a sum. The following code will help in deciding what you need sum or max value.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select max(weight) as MAX_WT, sum(Weight) as SUM_WT from sashelp.class;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The output will be like this&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2021-05-12 7.48.04 AM.png" style="width: 145px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/59267iB35957AA0A40C399/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2021-05-12 7.48.04 AM.png" alt="Screenshot 2021-05-12 7.48.04 AM.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 12 May 2021 11:49:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/To-write-a-code-that-finds-the-max-amount-before-the-last-amount/m-p/740765#M231457</guid>
      <dc:creator>Sajid01</dc:creator>
      <dc:date>2021-05-12T11:49:18Z</dc:date>
    </item>
    <item>
      <title>Re: To write a code that finds the max amount before the last amount in do until loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/To-write-a-code-that-finds-the-max-amount-before-the-last-amount/m-p/741013#M231590</link>
      <description>Hello kawakami,&lt;BR /&gt;Thanks for the response!&lt;BR /&gt;This outputs everything less than 1000.&lt;BR /&gt;I need only one observation: only the first observation which is less than 1000.&lt;BR /&gt;Please let me know if this makes sense.&lt;BR /&gt;Respectfully,&lt;BR /&gt;Blue Blue</description>
      <pubDate>Thu, 13 May 2021 04:42:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/To-write-a-code-that-finds-the-max-amount-before-the-last-amount/m-p/741013#M231590</guid>
      <dc:creator>GN0001</dc:creator>
      <dc:date>2021-05-13T04:42:45Z</dc:date>
    </item>
    <item>
      <title>Re: To write a code that finds the max amount before the last amount in do until loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/To-write-a-code-that-finds-the-max-amount-before-the-last-amount/m-p/741014#M231591</link>
      <description>Thanks for the response.&lt;BR /&gt;No, I don't want a sum.&lt;BR /&gt;Regards,&lt;BR /&gt;Blue Blue&lt;BR /&gt;</description>
      <pubDate>Thu, 13 May 2021 04:46:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/To-write-a-code-that-finds-the-max-amount-before-the-last-amount/m-p/741014#M231591</guid>
      <dc:creator>GN0001</dc:creator>
      <dc:date>2021-05-13T04:46:27Z</dc:date>
    </item>
    <item>
      <title>Re: To write a code that finds the max amount before the last amount in do until loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/To-write-a-code-that-finds-the-max-amount-before-the-last-amount/m-p/741033#M231607</link>
      <description>&lt;P&gt;How about this two codes?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Store in other variable for the last observation&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data increaseit;
  set salyr;
  do until (salary gt 1000);
    salary = salary + salary * 0.06;
    year = year + 1;
    output;
    salary2=salary;
  end;
Run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sort and flag the second one.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=increaseit out=temp;
  by descending year;
run;
data want;
  set temp;
  by descending year;
  if _n_=2 then flg=1;
run;
proc sort data=want;
  by year;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 May 2021 06:38:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/To-write-a-code-that-finds-the-max-amount-before-the-last-amount/m-p/741033#M231607</guid>
      <dc:creator>japelin</dc:creator>
      <dc:date>2021-05-13T06:38:02Z</dc:date>
    </item>
    <item>
      <title>Re: To write a code that finds the max amount before the last amount in do until loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/To-write-a-code-that-finds-the-max-amount-before-the-last-amount/m-p/741071#M231631</link>
      <description>&lt;P&gt;Make the following change to the second part.&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;Instead of
if _n_=2 then flg=1;
use 
if _n_=2 then output;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;The want data set will have only one record. I am giving a sample code below&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data salary;
input salary year;
datalines;
200 1990
;
run;
data increaseit;
  set salary;
  do until (salary gt 1000);
    salary = salary + salary * 0.06;
    year = year + 1;
    if not(salary gt 1000) then output;
  end;
Run;
proc sort data=increaseit out=temp;
  by descending year;
run;
data want;
  set temp;
  by descending year;
  if _n_=2 then output;
run;&lt;BR /&gt;proc&amp;nbsp;print&amp;nbsp;data=want;&lt;BR /&gt;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The out put will&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="forum.PNG" style="width: 174px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/59309iA34CA39282053B96/image-size/large?v=v2&amp;amp;px=999" role="button" title="forum.PNG" alt="forum.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 May 2021 12:04:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/To-write-a-code-that-finds-the-max-amount-before-the-last-amount/m-p/741071#M231631</guid>
      <dc:creator>Sajid01</dc:creator>
      <dc:date>2021-05-13T12:04:15Z</dc:date>
    </item>
  </channel>
</rss>

