<?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: how to interpret the program in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-interpret-the-program/m-p/800423#M314860</link>
    <description>&lt;P&gt;what is end=last on the second line means?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 06 Mar 2022 05:21:10 GMT</pubDate>
    <dc:creator>HeatherNewton</dc:creator>
    <dc:date>2022-03-06T05:21:10Z</dc:date>
    <item>
      <title>how to interpret the program</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-interpret-the-program/m-p/800406#M314845</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data lemon:
set pf_lemon end=last;
tot_up+up;
tot_down+down;
ar=tot_up/tot_down;
if last:
where sub_product='lemon';
run;&lt;/PRE&gt;&lt;P&gt;can you let me know how to interpret this program.. when are the third to fifth lines getting run? when if last?&amp;nbsp;&lt;/P&gt;&lt;P&gt;if it is not run, what would be tot_up, tot_down and ar?&lt;/P&gt;&lt;P&gt;what are initial values of tot_up and tot_down, null?&lt;/P&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;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 06 Mar 2022 03:08:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-interpret-the-program/m-p/800406#M314845</guid>
      <dc:creator>HeatherNewton</dc:creator>
      <dc:date>2022-03-06T03:08:55Z</dc:date>
    </item>
    <item>
      <title>Re: how to interpret the program</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-interpret-the-program/m-p/800416#M314854</link>
      <description>&lt;P&gt;Have you tried running this program? It contains a syntax error:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if last:&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Please correct your program, run it, then post the complete SAS log including code and notes. This will help you understand what it is doing.&lt;/P&gt;</description>
      <pubDate>Sun, 06 Mar 2022 04:23:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-interpret-the-program/m-p/800416#M314854</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2022-03-06T04:23:49Z</dc:date>
    </item>
    <item>
      <title>Re: how to interpret the program</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-interpret-the-program/m-p/800417#M314855</link>
      <description>&lt;P&gt;If there is no variable in the source data set pf_lemon that is named Tot_up or Tot_down, and there are variables in the source data set named then following two line would create a running total variable for up and down.&lt;/P&gt;
&lt;PRE&gt;tot_up+up;
tot_down+down;&lt;/PRE&gt;
&lt;P&gt;The 5th line calculates a ratio between the two values.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Assuming&lt;/STRONG&gt; my assumptions in the first line of my response is accurate the first value of the Tot_ variables is the first value of the up or down variable. Since AR is defined like any other&amp;nbsp; var= (calculation involving other variables); it gets the value from that calculation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Suggestion, make some dummy data and remove the the "if last", which by the way has a syntax error and the data step would not run. For educational purposes include one or missing values for the up or down variable in the test. Then look at the output.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A statement like:&amp;nbsp;&amp;nbsp; var + something; invokes and implied RETAIN for the variable variable Var.&lt;/P&gt;</description>
      <pubDate>Sun, 06 Mar 2022 04:29:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-interpret-the-program/m-p/800417#M314855</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-03-06T04:29:17Z</dc:date>
    </item>
    <item>
      <title>Re: how to interpret the program</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-interpret-the-program/m-p/800423#M314860</link>
      <description>&lt;P&gt;what is end=last on the second line means?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 06 Mar 2022 05:21:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-interpret-the-program/m-p/800423#M314860</guid>
      <dc:creator>HeatherNewton</dc:creator>
      <dc:date>2022-03-06T05:21:10Z</dc:date>
    </item>
    <item>
      <title>Re: how to interpret the program</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-interpret-the-program/m-p/800424#M314861</link>
      <description>&lt;P&gt;what is AR mentioned in your response?&lt;/P&gt;</description>
      <pubDate>Sun, 06 Mar 2022 05:24:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-interpret-the-program/m-p/800424#M314861</guid>
      <dc:creator>HeatherNewton</dc:creator>
      <dc:date>2022-03-06T05:24:10Z</dc:date>
    </item>
    <item>
      <title>Re: how to interpret the program</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-interpret-the-program/m-p/800426#M314863</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/416388"&gt;@HeatherNewton&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;what is AR mentioned in your response?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The variable you provided in the code:&lt;/P&gt;
&lt;PRE&gt;tot_down+down;
ar=tot_up/tot_down;&lt;/PRE&gt;</description>
      <pubDate>Sun, 06 Mar 2022 05:29:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-interpret-the-program/m-p/800426#M314863</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-03-06T05:29:29Z</dc:date>
    </item>
    <item>
      <title>Re: how to interpret the program</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-interpret-the-program/m-p/800428#M314865</link>
      <description>&lt;P&gt;End is just one of the SET statement options that creates a temporary variable for the duration of the data step that provides information from things on the SET statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Read details here:&amp;nbsp; &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/lestmtsref/p00hxg3x8lwivcn1f0e9axziw57y.htm" target="_blank"&gt;https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/lestmtsref/p00hxg3x8lwivcn1f0e9axziw57y.htm&lt;/A&gt;&lt;/P&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;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 06 Mar 2022 05:34:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-interpret-the-program/m-p/800428#M314865</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-03-06T05:34:02Z</dc:date>
    </item>
    <item>
      <title>Re: how to interpret the program</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-interpret-the-program/m-p/800430#M314867</link>
      <description>&lt;P&gt;It only calculates when if last is commented&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;it calculates nothing when if last is kept as it is, why?&lt;/P&gt;</description>
      <pubDate>Sun, 06 Mar 2022 06:09:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-interpret-the-program/m-p/800430#M314867</guid>
      <dc:creator>HeatherNewton</dc:creator>
      <dc:date>2022-03-06T06:09:25Z</dc:date>
    </item>
    <item>
      <title>Re: how to interpret the program</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-interpret-the-program/m-p/800431#M314868</link>
      <description>&lt;P&gt;no actually results are the same where the line for lemon has ar calculated&lt;/P&gt;&lt;P&gt;without or with if last statement&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;what is the significance of if last statement here?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 06 Mar 2022 06:16:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-interpret-the-program/m-p/800431#M314868</guid>
      <dc:creator>HeatherNewton</dc:creator>
      <dc:date>2022-03-06T06:16:56Z</dc:date>
    </item>
    <item>
      <title>Re: how to interpret the program</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-interpret-the-program/m-p/800433#M314869</link>
      <description>&lt;P&gt;WHERE is a statement that cannot be made conditional, so it is bad practice to put it after a subsetting IF.&lt;/P&gt;
&lt;P&gt;For better understanding, and more efficiency, the code should be like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data lemon:
set pf_lemon end=last; /* END= defines a boolean variable that will be true when the last observation is processed */
where sub_product = 'lemon'; /* WHERE tells the dataset engine to filter observations according to the condition */
tot_up + up;
tot_down + down; /* Two SUM statements, causing an implicit RETAIN of the variables */
if last; /* All code after the subsetting IF is executed only when the condition is met */
/* This includes the implicit OUTPUT at the end of the data step iteration! */
ar = tot_up / tot_down; /* I moved this after the IF for efficiency */
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Also note that I inserted blanks between operators and operands for better readability.&lt;/P&gt;</description>
      <pubDate>Sun, 06 Mar 2022 06:19:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-interpret-the-program/m-p/800433#M314869</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-03-06T06:19:36Z</dc:date>
    </item>
  </channel>
</rss>

