<?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 Generating an accumulating column  from Data Manipulation 9.4  practice=p202p04.sas in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Generating-an-accumulating-column-from-Data-Manipulation-9-4/m-p/968264#M43315</link>
    <description>&lt;P&gt;*Hi,&amp;nbsp; This is the lesson and there are two solutions below.&amp;nbsp; In the first solution please let me know if you need .... count+1? both solutions are the same without it.&amp;nbsp; If it is included, what is the reasoning. Thank you!! ********************************************************;&lt;BR /&gt;* LESSON 2, PRACTICE 1 *;&lt;BR /&gt;* a) Open the PG2.NP_YEARLYTRAFFIC table. Notice the *;&lt;BR /&gt;* Count column records the number of cars that have *;&lt;BR /&gt;* passed through a particular Location. *;&lt;BR /&gt;* b) Modify the DATA step to create a column, totTraffic,*;&lt;BR /&gt;* that is the running total of Count. *;&lt;BR /&gt;* b) Keep the ParkName, Location, Count, and *;&lt;BR /&gt;* totTraffic columns in the output table. *;&lt;BR /&gt;* c) Format totTraffic so values are displayed with *;&lt;BR /&gt;* commas. *;&lt;BR /&gt;***********************************************************;&lt;/P&gt;&lt;P&gt;data totalTraffic ;&lt;BR /&gt;set pg2.np_yearlyTraffic;&lt;BR /&gt;Count+1; *Running Total of Count */;&lt;BR /&gt;retain totTraffic 0;&lt;BR /&gt;totTraffic+Count;&lt;BR /&gt;format totTraffic comma12.;&lt;BR /&gt;keep ParkName Location Count totTraffic;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;/*OR*/&lt;/P&gt;&lt;P&gt;data totalTraffic;&lt;BR /&gt;set pg2.np_yearlytraffic;&lt;BR /&gt;totTraffic+Count;&lt;BR /&gt;keep ParkName Location Count totTraffic;&lt;BR /&gt;format totTraffic comma12.;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 05 Jun 2025 14:16:28 GMT</pubDate>
    <dc:creator>heatherml20</dc:creator>
    <dc:date>2025-06-05T14:16:28Z</dc:date>
    <item>
      <title>Generating an accumulating column  from Data Manipulation 9.4  practice=p202p04.sas</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Generating-an-accumulating-column-from-Data-Manipulation-9-4/m-p/968264#M43315</link>
      <description>&lt;P&gt;*Hi,&amp;nbsp; This is the lesson and there are two solutions below.&amp;nbsp; In the first solution please let me know if you need .... count+1? both solutions are the same without it.&amp;nbsp; If it is included, what is the reasoning. Thank you!! ********************************************************;&lt;BR /&gt;* LESSON 2, PRACTICE 1 *;&lt;BR /&gt;* a) Open the PG2.NP_YEARLYTRAFFIC table. Notice the *;&lt;BR /&gt;* Count column records the number of cars that have *;&lt;BR /&gt;* passed through a particular Location. *;&lt;BR /&gt;* b) Modify the DATA step to create a column, totTraffic,*;&lt;BR /&gt;* that is the running total of Count. *;&lt;BR /&gt;* b) Keep the ParkName, Location, Count, and *;&lt;BR /&gt;* totTraffic columns in the output table. *;&lt;BR /&gt;* c) Format totTraffic so values are displayed with *;&lt;BR /&gt;* commas. *;&lt;BR /&gt;***********************************************************;&lt;/P&gt;&lt;P&gt;data totalTraffic ;&lt;BR /&gt;set pg2.np_yearlyTraffic;&lt;BR /&gt;Count+1; *Running Total of Count */;&lt;BR /&gt;retain totTraffic 0;&lt;BR /&gt;totTraffic+Count;&lt;BR /&gt;format totTraffic comma12.;&lt;BR /&gt;keep ParkName Location Count totTraffic;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;/*OR*/&lt;/P&gt;&lt;P&gt;data totalTraffic;&lt;BR /&gt;set pg2.np_yearlytraffic;&lt;BR /&gt;totTraffic+Count;&lt;BR /&gt;keep ParkName Location Count totTraffic;&lt;BR /&gt;format totTraffic comma12.;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Jun 2025 14:16:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Generating-an-accumulating-column-from-Data-Manipulation-9-4/m-p/968264#M43315</guid>
      <dc:creator>heatherml20</dc:creator>
      <dc:date>2025-06-05T14:16:28Z</dc:date>
    </item>
    <item>
      <title>Re: Generating an accumulating column  from Data Manipulation 9.4  practice=p202p04.sas</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Generating-an-accumulating-column-from-Data-Manipulation-9-4/m-p/968265#M43316</link>
      <description>&lt;P&gt;Depends on the source table.&lt;/P&gt;
&lt;P&gt;Second example relies on a count column in the source, the first doesn't.&lt;/P&gt;</description>
      <pubDate>Thu, 05 Jun 2025 14:42:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Generating-an-accumulating-column-from-Data-Manipulation-9-4/m-p/968265#M43316</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2025-06-05T14:42:51Z</dc:date>
    </item>
    <item>
      <title>Re: Generating an accumulating column  from Data Manipulation 9.4  practice=p202p04.sas</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Generating-an-accumulating-column-from-Data-Manipulation-9-4/m-p/968279#M43317</link>
      <description>&lt;P&gt;Hi:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; You might want to go back and revisit the lectures on the RETAIN statement and the SUM statement. In this code (I changed the output data table names with 1 and 2), You can see that the only difference is the RETAIN statement. The fact that Example 2 works the same as Example 1 tells you something about how the SUM statement works.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Cynthia_sas_1-1749137255622.jpeg" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/107656i6198FCA9843D716D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Cynthia_sas_1-1749137255622.jpeg" alt="Cynthia_sas_1-1749137255622.jpeg" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Notice that the lecture on the SUM statement explains that the SUM statement does an automatic RETAIN.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Cynthia_sas_0-1749136733426.jpeg" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/107654i32235F003E0BCF02/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Cynthia_sas_0-1749136733426.jpeg" alt="Cynthia_sas_0-1749136733426.jpeg" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thus, the RETAIN statement in the first example is not necessary for purposes of having the program work. On the other hand, using a RETAIN statement, even with a SUM statement makes it clearer that totTraffic is the variable being accumulated and retained.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Understanding when you need to use RETAIN and when it's not absolutely required is one of the objectives for this practice. However, you can break the SUM statement like this:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Cynthia_sas_2-1749138032222.jpeg" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/107657iD454369CD7878A00/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Cynthia_sas_2-1749138032222.jpeg" alt="Cynthia_sas_2-1749138032222.jpeg" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Learning when to use the RETAIN statement and how the SUM statement works is one of the goals of this Lesson.&lt;/P&gt;
&lt;P&gt;Cynthia&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Jun 2025 16:25:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Generating-an-accumulating-column-from-Data-Manipulation-9-4/m-p/968279#M43317</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2025-06-05T16:25:47Z</dc:date>
    </item>
    <item>
      <title>Re: Generating an accumulating column  from Data Manipulation 9.4  practice=p202p04.sas</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Generating-an-accumulating-column-from-Data-Manipulation-9-4/m-p/968327#M43318</link>
      <description>Hi Cynthia,&lt;BR /&gt;&lt;BR /&gt;My question was this: do I need the Count+1 in Example 1. You took it out so I assume we don't need it. I am referring to my Example 1:&lt;BR /&gt;data totalTraffic ;&lt;BR /&gt;set pg2.np_yearlyTraffic;&lt;BR /&gt;Count+1;&lt;BR /&gt;retain totTraffic 0;&lt;BR /&gt;totTraffic+Count;&lt;BR /&gt;format totTraffic comma12.;&lt;BR /&gt;keep ParkName Location Count totTraffic;&lt;BR /&gt;run;</description>
      <pubDate>Fri, 06 Jun 2025 13:12:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Generating-an-accumulating-column-from-Data-Manipulation-9-4/m-p/968327#M43318</guid>
      <dc:creator>heatherml20</dc:creator>
      <dc:date>2025-06-06T13:12:12Z</dc:date>
    </item>
    <item>
      <title>Re: Generating an accumulating column  from Data Manipulation 9.4  practice=p202p04.sas</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Generating-an-accumulating-column-from-Data-Manipulation-9-4/m-p/968338#M43319</link>
      <description>Hi:&lt;BR /&gt;  Reread the instructions for the practice again and then run a PROC CONTENTS on the pg2.np_yearlyTraffic data table. In the instructions, there is a sentence that says "Notice that the Count column records the number of cars that have passed through a particular location." So, you need to use the COUNT column from the starting data to create totTraffic in this instance. In a different scenario, you might create your own variable, but it is not necessary in this case.&lt;BR /&gt;Cynthia</description>
      <pubDate>Fri, 06 Jun 2025 14:31:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Generating-an-accumulating-column-from-Data-Manipulation-9-4/m-p/968338#M43319</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2025-06-06T14:31:30Z</dc:date>
    </item>
  </channel>
</rss>

