<?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 Performing a Calculation Based on the Last Observation??? in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Performing-a-Calculation-Based-on-the-Last-Observation/m-p/88443#M25241</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi!&amp;nbsp; I need to do the following... go through a data sheet and if a certain condition occurs increase the count of a variable&lt;/P&gt;&lt;P&gt;I need to do this for four variables - (given four different conditions)&lt;/P&gt;&lt;P&gt;Then I need to plug in the final value of the four different count variables into a macro.&amp;nbsp; My issue is that SAS stores a count variable as 1,2,3,4,5,6 and not just the end total 6.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So given the following code&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data work&lt;/P&gt;&lt;P&gt;set testxls.'Sheet1$'n ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if X ~= . and Y = 'QWE' then L1 + 1; &lt;/P&gt;&lt;P&gt;if X = . and Y = 'QWE' then L2 + 1* ;&lt;/P&gt;&lt;P&gt;if X ~= . and Y ~= 'ABC' then L3 + 1; &lt;/P&gt;&lt;P&gt;if X = . and Y ~= 'ABC' then L4 + 1; &lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So in this instance L1. eg, is 1,1,1,1,1,1,1,2,3,3,4,5,6,7&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now i have a macro (which i cant change) with the format&lt;/P&gt;&lt;P&gt;macro XCV(in,out)&lt;/P&gt;&lt;P&gt;data &amp;amp;out; set &amp;amp;in;&lt;/P&gt;&lt;P&gt;if (L1 = 0 or L2 = 0 or L3 =0 or L4=0) then do;&lt;/P&gt;&lt;P&gt;blah blah blah&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;else do;&lt;/P&gt;&lt;P&gt;blah blah blah&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;????????&lt;/P&gt;&lt;P&gt;How do I isolate the final values for L1 - L4?&amp;nbsp; If I do %XYZ(work,out).&amp;nbsp; The out output file contains functions for ever value of L1-L4 i.e for L1 1,1,1,1,1,1,1,2,3,3,4,5,6,7&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 07 Oct 2012 02:19:08 GMT</pubDate>
    <dc:creator>NeutrinoSAS</dc:creator>
    <dc:date>2012-10-07T02:19:08Z</dc:date>
    <item>
      <title>Performing a Calculation Based on the Last Observation???</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Performing-a-Calculation-Based-on-the-Last-Observation/m-p/88443#M25241</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi!&amp;nbsp; I need to do the following... go through a data sheet and if a certain condition occurs increase the count of a variable&lt;/P&gt;&lt;P&gt;I need to do this for four variables - (given four different conditions)&lt;/P&gt;&lt;P&gt;Then I need to plug in the final value of the four different count variables into a macro.&amp;nbsp; My issue is that SAS stores a count variable as 1,2,3,4,5,6 and not just the end total 6.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So given the following code&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data work&lt;/P&gt;&lt;P&gt;set testxls.'Sheet1$'n ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if X ~= . and Y = 'QWE' then L1 + 1; &lt;/P&gt;&lt;P&gt;if X = . and Y = 'QWE' then L2 + 1* ;&lt;/P&gt;&lt;P&gt;if X ~= . and Y ~= 'ABC' then L3 + 1; &lt;/P&gt;&lt;P&gt;if X = . and Y ~= 'ABC' then L4 + 1; &lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So in this instance L1. eg, is 1,1,1,1,1,1,1,2,3,3,4,5,6,7&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now i have a macro (which i cant change) with the format&lt;/P&gt;&lt;P&gt;macro XCV(in,out)&lt;/P&gt;&lt;P&gt;data &amp;amp;out; set &amp;amp;in;&lt;/P&gt;&lt;P&gt;if (L1 = 0 or L2 = 0 or L3 =0 or L4=0) then do;&lt;/P&gt;&lt;P&gt;blah blah blah&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;else do;&lt;/P&gt;&lt;P&gt;blah blah blah&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;????????&lt;/P&gt;&lt;P&gt;How do I isolate the final values for L1 - L4?&amp;nbsp; If I do %XYZ(work,out).&amp;nbsp; The out output file contains functions for ever value of L1-L4 i.e for L1 1,1,1,1,1,1,1,2,3,3,4,5,6,7&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 07 Oct 2012 02:19:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Performing-a-Calculation-Based-on-the-Last-Observation/m-p/88443#M25241</guid>
      <dc:creator>NeutrinoSAS</dc:creator>
      <dc:date>2012-10-07T02:19:08Z</dc:date>
    </item>
    <item>
      <title>Re: Performing a Calculation Based on the Last Observation???</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Performing-a-Calculation-Based-on-the-Last-Observation/m-p/88444#M25242</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;If I understand you correctly, you need one more data step pass to fix L1-L4 on their maximum values, or switch to proc SQL:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data work;&lt;/P&gt;&lt;P&gt;do until (last);&lt;/P&gt;&lt;P&gt;set testxls.'Sheet1$'n end=last;&lt;/P&gt;&lt;P&gt;if X ~= . and Y = 'QWE' then L1 + 1;&lt;/P&gt;&lt;P&gt;if X = . and Y = 'QWE' then L2 + 1* ;&lt;/P&gt;&lt;P&gt;if X ~= . and Y ~= 'ABC' then L3 + 1;&lt;/P&gt;&lt;P&gt;if X = . and Y ~= 'ABC' then L4 + 1;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;do until (last);&lt;/P&gt;&lt;P&gt;set testxls.'Sheet1$'n end=last;&lt;/P&gt;&lt;P&gt;output;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/*Or Modify your code to proc sql*/&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp; create table work as&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; select *,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sum (X ~= . and Y = 'QWE') as L1,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sum (X = . and Y = 'QWE') as L2,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sum (X ~= . and Y ~= 'ABC') as L3,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sum (X = . and Y ~= 'ABC' ) as L4&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from testxls.'Sheet1$'n&amp;nbsp;&amp;nbsp;&amp;nbsp; ;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then use this 'work' in your downstream Macro.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Haikuo&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 07 Oct 2012 02:48:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Performing-a-Calculation-Based-on-the-Last-Observation/m-p/88444#M25242</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2012-10-07T02:48:02Z</dc:date>
    </item>
    <item>
      <title>Re: Performing a Calculation Based on the Last Observation???</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Performing-a-Calculation-Based-on-the-Last-Observation/m-p/88445#M25243</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Why not just modify your code to something like? (note: I can't test this tonight, but I would assume that the end option works with spreadsheets):&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;data work&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;set testxls.'Sheet1$'n end=eof;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp; if X ~= . and Y = 'QWE' then L1 + 1;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp; if X = . and Y = 'QWE' then L2 + 1* ;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp; if X ~= . and Y ~= 'ABC' then L3 + 1;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp; if X = . and Y ~= 'ABC' then L4 + 1;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp; if eof then output;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 07 Oct 2012 02:53:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Performing-a-Calculation-Based-on-the-Last-Observation/m-p/88445#M25243</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2012-10-07T02:53:58Z</dc:date>
    </item>
  </channel>
</rss>

