<?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: Significance of the last.var in my program. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Significance-of-the-last-var-in-my-program/m-p/975290#M378079</link>
    <description>&lt;P&gt;I&amp;nbsp;&lt;U&gt;&lt;STRONG&gt;STRONGLY&lt;/STRONG&gt;&lt;/U&gt; suggest that you study the documentation (Maxim 1!) of the&amp;nbsp;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lestmtsref/p0yeyftk8ftuckn1o5qzy53284gz.htm" target="_blank" rel="noopener"&gt;BY Statement&lt;/A&gt;&amp;nbsp;and&amp;nbsp;&lt;A href="https://documentation.sas.com/doc/en/lrcon/9.4/n138da4gme3zb7n1nifpfhqv7clq.htm" target="_blank" rel="noopener"&gt;BY-Group Processing in the DATA Step&lt;/A&gt;.&lt;/P&gt;</description>
    <pubDate>Wed, 17 Sep 2025 22:14:44 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2025-09-17T22:14:44Z</dc:date>
    <item>
      <title>Significance of the last.var in my program.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Significance-of-the-last-var-in-my-program/m-p/975272#M378070</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I am getting the right answers to my program, but I am not able to understand what the last.code is actually doing.&lt;/P&gt;&lt;P&gt;In below pic if last.code; is included.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SASsusrik_0-1758130246153.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/110041iF1CEABAF0CD8FC24/image-size/medium?v=v2&amp;amp;px=400" role="button" title="SASsusrik_0-1758130246153.png" alt="SASsusrik_0-1758130246153.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;the output is:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SASsusrik_1-1758130389434.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/110042i7D36A4AC77ED0279/image-size/medium?v=v2&amp;amp;px=400" role="button" title="SASsusrik_1-1758130389434.png" alt="SASsusrik_1-1758130389434.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;In the second program, I omitted the last.code; statement. The output is as follows:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SASsusrik_2-1758130496404.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/110043i7B97DE11715A4C55/image-size/medium?v=v2&amp;amp;px=400" role="button" title="SASsusrik_2-1758130496404.png" alt="SASsusrik_2-1758130496404.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I am not able to understand why removing just the last.code; is not grouping by code. Would appreciate help in understanding how this last.var works. TIA!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Sep 2025 17:35:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Significance-of-the-last-var-in-my-program/m-p/975272#M378070</guid>
      <dc:creator>SASsusrik</dc:creator>
      <dc:date>2025-09-17T17:35:47Z</dc:date>
    </item>
    <item>
      <title>Re: Significance of the last.var in my program.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Significance-of-the-last-var-in-my-program/m-p/975273#M378071</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if last.code;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This IF statement tells the data step to output a record to the data set. Other records are not output.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Which record(s) get output? The last record that has each value of combination of variables ID and CODE.&amp;nbsp; In this case, the last record contains number of observations and total miles for each value of the combination of variables ID and CODE.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you omit this IF statement, then all records are output.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Sep 2025 17:54:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Significance-of-the-last-var-in-my-program/m-p/975273#M378071</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2025-09-17T17:54:04Z</dc:date>
    </item>
    <item>
      <title>Re: Significance of the last.var in my program.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Significance-of-the-last-var-in-my-program/m-p/975274#M378072</link>
      <description>&lt;P&gt;This is a&amp;nbsp;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lestmtsref/p1cxl8ifdt8u0gn12wqbji8o5fq1.htm" target="_blank" rel="noopener"&gt;Subsetting IF&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the condition does not evaluate to true, the rest of the code is skipped for the current iteration of the DATA step, and execution starts for the next iteration. Or, if you want to say so, the program pointer jumps to the "top" of the DATA step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;first. and last. variables are created for every variable included in the BY statement. The last. is set to true when the last observation for the current group of the particular BY variable is read.&lt;/P&gt;</description>
      <pubDate>Wed, 17 Sep 2025 18:06:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Significance-of-the-last-var-in-my-program/m-p/975274#M378072</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2025-09-17T18:06:13Z</dc:date>
    </item>
    <item>
      <title>Re: Significance of the last.var in my program.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Significance-of-the-last-var-in-my-program/m-p/975279#M378073</link>
      <description>&lt;P&gt;Oh awesome, Thanks Paige,&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I have another follow up question reg the initialization of variables in the data step:&lt;BR /&gt;this is the code :&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SASsusrik_0-1758135559991.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/110044i1945A22E83E3A7DC/image-size/medium?v=v2&amp;amp;px=400" role="button" title="SASsusrik_0-1758135559991.png" alt="SASsusrik_0-1758135559991.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;and the partial output (which is what I am looking for):&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SASsusrik_1-1758135605447.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/110045i919D3FE3C40CA5BD/image-size/medium?v=v2&amp;amp;px=400" role="button" title="SASsusrik_1-1758135605447.png" alt="SASsusrik_1-1758135605447.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;However if I do this: explicitly state a var statement and use assignment then it prints booksales as empty values. The total sales is. correct however.&amp;nbsp; I presume I have initialized the variables in the if first.date conditional. Can you please shed some light on this as to why the booksales is showing as empty. TIA!!&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SASsusrik_2-1758135732316.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/110046i42CA1191869ECBA2/image-size/medium?v=v2&amp;amp;px=400" role="button" title="SASsusrik_2-1758135732316.png" alt="SASsusrik_2-1758135732316.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;partial output&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SASsusrik_3-1758135762287.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/110047i2EDFAFE244DCC0D9/image-size/medium?v=v2&amp;amp;px=400" role="button" title="SASsusrik_3-1758135762287.png" alt="SASsusrik_3-1758135762287.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Sep 2025 19:04:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Significance-of-the-last-var-in-my-program/m-p/975279#M378073</guid>
      <dc:creator>SASsusrik</dc:creator>
      <dc:date>2025-09-17T19:04:22Z</dc:date>
    </item>
    <item>
      <title>Re: Significance of the last.var in my program.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Significance-of-the-last-var-in-my-program/m-p/975280#M378074</link>
      <description>&lt;P&gt;Also if I did not have a if last.code statement, I am presuming it automatically ouputs the last variable values from the first.code statement. I hope I am correct in assuming this. TIA!&lt;/P&gt;</description>
      <pubDate>Wed, 17 Sep 2025 19:08:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Significance-of-the-last-var-in-my-program/m-p/975280#M378074</guid>
      <dc:creator>SASsusrik</dc:creator>
      <dc:date>2025-09-17T19:08:13Z</dc:date>
    </item>
    <item>
      <title>Re: Significance of the last.var in my program.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Significance-of-the-last-var-in-my-program/m-p/975281#M378075</link>
      <description>&lt;P&gt;This construct creates cumulative sums, where on every record SALES is added to the value of BOOKSALES from the previous record.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;booksales + sales;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It keeps adding sales into booksales on every record. But you don't want that, you want to set the booksales back to zero for each date.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But since you don't have a variable named SALES, but you do have a variable names BOOKSALES, I don't think the code as written would work. I think you want&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;sales+booksales;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then last.date outputs the final cumulative sales to the data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Lastly, you are struggling with coding that is much simpler in PROC SUMMARY. Since SAS has done the hard work of figuring out how to compute sales across many variables, and then created PROC SUMMARY which lets you figure out the total sales in a DATE (or any other variable you want like COUNTRY or STATE or any other variable) with much less programming and much less logic to trip you up, I suggest you learn and use PROC SUMMARY for this task. Note that if you had 10 variables instead of these 4, you just add the variables into the VAR statement, you don't need to set each one to zero and then do the summation on each variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=datetypesort nway;
    class date;
    var booksales cardsales persales totalsales;
    output out=daysales sum=;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Sep 2025 20:59:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Significance-of-the-last-var-in-my-program/m-p/975281#M378075</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2025-09-17T20:59:15Z</dc:date>
    </item>
    <item>
      <title>Re: Significance of the last.var in my program.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Significance-of-the-last-var-in-my-program/m-p/975287#M378077</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;booksales = booksales + sales;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;is a simple assignment statement, with a calculation on the right side of the equal sign.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;booksales + sales;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;is a Sum statement.&lt;/P&gt;
&lt;P&gt;A Sum statement implies an automatic RETAIN and will treat missing arguments as zero.&lt;/P&gt;
&lt;P&gt;The normal assignment does neither, and so your booksales is set to missing at the second observation of a group.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=datetypesort nway;
class date merchtype;
var sales;
output out=daysales sum()=;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want the wide structure, you can transpose this or use PROC REPORT with ACROSS.&lt;/P&gt;</description>
      <pubDate>Wed, 17 Sep 2025 20:31:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Significance-of-the-last-var-in-my-program/m-p/975287#M378077</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2025-09-17T20:31:29Z</dc:date>
    </item>
    <item>
      <title>Re: Significance of the last.var in my program.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Significance-of-the-last-var-in-my-program/m-p/975288#M378078</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/476757"&gt;@SASsusrik&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Also if I did not have a if last.code statement, I am presuming it automatically ouputs the last variable values from the first.code statement. I hope I am correct in assuming this. TIA!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The way you have written this, and if I am understanding you properly, I would say the answer is NO. You are not correct. The command&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if last.date;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;causes only the last record for each date to be output. If you leave this out, then every record for every date is output. It works independently of any first.date command.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;And its not 'last.code', and it is not 'last.var' which won't work here, it is last.date.&lt;/P&gt;</description>
      <pubDate>Wed, 17 Sep 2025 21:17:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Significance-of-the-last-var-in-my-program/m-p/975288#M378078</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2025-09-17T21:17:01Z</dc:date>
    </item>
    <item>
      <title>Re: Significance of the last.var in my program.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Significance-of-the-last-var-in-my-program/m-p/975290#M378079</link>
      <description>&lt;P&gt;I&amp;nbsp;&lt;U&gt;&lt;STRONG&gt;STRONGLY&lt;/STRONG&gt;&lt;/U&gt; suggest that you study the documentation (Maxim 1!) of the&amp;nbsp;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lestmtsref/p0yeyftk8ftuckn1o5qzy53284gz.htm" target="_blank" rel="noopener"&gt;BY Statement&lt;/A&gt;&amp;nbsp;and&amp;nbsp;&lt;A href="https://documentation.sas.com/doc/en/lrcon/9.4/n138da4gme3zb7n1nifpfhqv7clq.htm" target="_blank" rel="noopener"&gt;BY-Group Processing in the DATA Step&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Wed, 17 Sep 2025 22:14:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Significance-of-the-last-var-in-my-program/m-p/975290#M378079</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2025-09-17T22:14:44Z</dc:date>
    </item>
    <item>
      <title>Re: Significance of the last.var in my program.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Significance-of-the-last-var-in-my-program/m-p/975291#M378080</link>
      <description>&lt;P&gt;Thanks Paige, appreciate your help in understanding the concepts and how they work.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Sep 2025 22:31:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Significance-of-the-last-var-in-my-program/m-p/975291#M378080</guid>
      <dc:creator>SASsusrik</dc:creator>
      <dc:date>2025-09-17T22:31:35Z</dc:date>
    </item>
    <item>
      <title>Re: Significance of the last.var in my program.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Significance-of-the-last-var-in-my-program/m-p/975292#M378081</link>
      <description>&lt;P&gt;Thanks Kurt, will read up on those links! Appreciate it!&lt;/P&gt;</description>
      <pubDate>Wed, 17 Sep 2025 22:32:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Significance-of-the-last-var-in-my-program/m-p/975292#M378081</guid>
      <dc:creator>SASsusrik</dc:creator>
      <dc:date>2025-09-17T22:32:03Z</dc:date>
    </item>
    <item>
      <title>Re: Significance of the last.var in my program.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Significance-of-the-last-var-in-my-program/m-p/975293#M378082</link>
      <description>&lt;P&gt;Sure, I am on this chapter trying to learn these concepts and was working out some homework problems. I will look up proc.summary too. TY!&lt;/P&gt;</description>
      <pubDate>Wed, 17 Sep 2025 22:33:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Significance-of-the-last-var-in-my-program/m-p/975293#M378082</guid>
      <dc:creator>SASsusrik</dc:creator>
      <dc:date>2025-09-17T22:33:34Z</dc:date>
    </item>
    <item>
      <title>Re: Significance of the last.var in my program.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Significance-of-the-last-var-in-my-program/m-p/975294#M378083</link>
      <description>&lt;P&gt;Also I am sorry the problem does ask for the booksales. I did not share the problem statement. But I do get the idea of what you are trying to convey. TY Paige!&lt;/P&gt;</description>
      <pubDate>Wed, 17 Sep 2025 22:35:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Significance-of-the-last-var-in-my-program/m-p/975294#M378083</guid>
      <dc:creator>SASsusrik</dc:creator>
      <dc:date>2025-09-17T22:35:31Z</dc:date>
    </item>
  </channel>
</rss>

