<?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 Calculating cumulative sum in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Calculating-cumulative-sum/m-p/831422#M328539</link>
    <description>&lt;P&gt;I am facing cumulative sum calculation. In my dataset, the columns to be summed are something like Cycle_1 to Cycle_65.&lt;BR /&gt;My program works to calculate the cumulative from cycle_1 to cycle_9. However, something is wrong from cycle_10.&lt;BR /&gt;In my previous dataset, the column VISIT is a character type .&lt;BR /&gt;Below my program:&lt;BR /&gt;Data Test2;&lt;BR /&gt;SET Test1;&lt;BR /&gt;BY ID _VISIT_;&lt;BR /&gt;ATTRIB VISIT LABEL = "Visit" FORMAT = $50. ;&lt;BR /&gt;ATTRIB CUMUL LABEL = "Cumulative sum by cycle" FORMAT = BEST12. ;&lt;BR /&gt;VISIT = SUBSTR(_VISIT_,1,8) ;&lt;BR /&gt;IF FIRST.ID THEN CUMUL = VALUE ;&lt;BR /&gt;ELSE CUMUL + VALUE ;&lt;BR /&gt;DROP VALUE;&lt;BR /&gt;RUN ;&lt;/P&gt;&lt;P&gt;When the program , run , I have an output below.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ndamo_0-1662046392102.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/74935iC36E5A83E6D1A338/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ndamo_0-1662046392102.png" alt="ndamo_0-1662046392102.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;So I need your help because I did not found were's the issues.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many thanks&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 01 Sep 2022 15:35:18 GMT</pubDate>
    <dc:creator>ndamo</dc:creator>
    <dc:date>2022-09-01T15:35:18Z</dc:date>
    <item>
      <title>Calculating cumulative sum</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-cumulative-sum/m-p/831422#M328539</link>
      <description>&lt;P&gt;I am facing cumulative sum calculation. In my dataset, the columns to be summed are something like Cycle_1 to Cycle_65.&lt;BR /&gt;My program works to calculate the cumulative from cycle_1 to cycle_9. However, something is wrong from cycle_10.&lt;BR /&gt;In my previous dataset, the column VISIT is a character type .&lt;BR /&gt;Below my program:&lt;BR /&gt;Data Test2;&lt;BR /&gt;SET Test1;&lt;BR /&gt;BY ID _VISIT_;&lt;BR /&gt;ATTRIB VISIT LABEL = "Visit" FORMAT = $50. ;&lt;BR /&gt;ATTRIB CUMUL LABEL = "Cumulative sum by cycle" FORMAT = BEST12. ;&lt;BR /&gt;VISIT = SUBSTR(_VISIT_,1,8) ;&lt;BR /&gt;IF FIRST.ID THEN CUMUL = VALUE ;&lt;BR /&gt;ELSE CUMUL + VALUE ;&lt;BR /&gt;DROP VALUE;&lt;BR /&gt;RUN ;&lt;/P&gt;&lt;P&gt;When the program , run , I have an output below.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ndamo_0-1662046392102.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/74935iC36E5A83E6D1A338/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ndamo_0-1662046392102.png" alt="ndamo_0-1662046392102.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;So I need your help because I did not found were's the issues.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many thanks&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Sep 2022 15:35:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-cumulative-sum/m-p/831422#M328539</guid>
      <dc:creator>ndamo</dc:creator>
      <dc:date>2022-09-01T15:35:18Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating cumulative sum</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-cumulative-sum/m-p/831424#M328541</link>
      <description>&lt;P&gt;The code you posted does not appear to have anything to do with the variables in the photograph you attached.&lt;/P&gt;
&lt;P&gt;Is the photograph the input data?&amp;nbsp; Where is the ID and _VISIT_ and VALUE variables the code is using?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please post input data as TEXT , preferable as a working SAS data step.&lt;/P&gt;
&lt;P&gt;Show the desired output data as well.&amp;nbsp; Preferable in the same way.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Sep 2022 15:43:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-cumulative-sum/m-p/831424#M328541</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-09-01T15:43:58Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating cumulative sum</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-cumulative-sum/m-p/831435#M328547</link>
      <description>&lt;P&gt;Hi &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yes because in my dataset Test1 I have someting like :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="407px"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="102.719px" height="57px"&gt;ID&lt;/TD&gt;
&lt;TD width="210.484px" height="57px"&gt;_VISIT_&lt;/TD&gt;
&lt;TD width="92.7969px" height="57px"&gt;VALUE&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="102.719px" height="57px"&gt;NNN-NNN&lt;/TD&gt;
&lt;TD width="210.484px" height="57px"&gt;Cycle 1 Treatment Administration&lt;/TD&gt;
&lt;TD width="92.7969px" height="57px"&gt;525&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="102.719px" height="57px"&gt;NNN-NNN&lt;/TD&gt;
&lt;TD width="210.484px" height="57px"&gt;Cycle 10 Treatment Administration&lt;/TD&gt;
&lt;TD width="92.7969px" height="57px"&gt;525&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="102.719px" height="57px"&gt;NNN-NNN&lt;/TD&gt;
&lt;TD width="210.484px" height="57px"&gt;Cycle 2 Treatment Administration&lt;/TD&gt;
&lt;TD width="92.7969px" height="57px"&gt;525&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="102.719px" height="57px"&gt;NNN-NNN&lt;/TD&gt;
&lt;TD width="210.484px" height="57px"&gt;Cycle 3 Treatment Administration&lt;/TD&gt;
&lt;TD width="92.7969px" height="57px"&gt;275&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="102.719px" height="57px"&gt;NNN-NNN&lt;/TD&gt;
&lt;TD width="210.484px" height="57px"&gt;Cycle 4 Treatment Administration&lt;/TD&gt;
&lt;TD width="92.7969px" height="57px"&gt;525&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="102.719px" height="57px"&gt;NNN-NNN&lt;/TD&gt;
&lt;TD width="210.484px" height="57px"&gt;Cycle 5 Treatment Administration&lt;/TD&gt;
&lt;TD width="92.7969px" height="57px"&gt;525&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="102.719px" height="57px"&gt;NNN-NNN&lt;/TD&gt;
&lt;TD width="210.484px" height="57px"&gt;Cycle 6 Treatment Administration&lt;/TD&gt;
&lt;TD width="92.7969px" height="57px"&gt;525&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="102.719px" height="57px"&gt;NNN-NNN&lt;/TD&gt;
&lt;TD width="210.484px" height="57px"&gt;Cycle 7 Treatment Administration&lt;/TD&gt;
&lt;TD width="92.7969px" height="57px"&gt;525&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="102.719px" height="57px"&gt;NNN-NNN&lt;/TD&gt;
&lt;TD width="210.484px" height="57px"&gt;Cycle 8 Treatment Administration&lt;/TD&gt;
&lt;TD width="92.7969px" height="57px"&gt;525&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="102.719px" height="57px"&gt;NNN-NNN&lt;/TD&gt;
&lt;TD width="210.484px" height="57px"&gt;Cycle 9 Treatment Administration&lt;/TD&gt;
&lt;TD width="92.7969px" height="57px"&gt;525&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In my dataset Test2&amp;nbsp; , I have created column visit to&amp;nbsp; get only the text "cycle" and its number . Maybe the SUBSTR function was not correctly worked.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Sep 2022 16:26:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-cumulative-sum/m-p/831435#M328547</guid>
      <dc:creator>ndamo</dc:creator>
      <dc:date>2022-09-01T16:26:07Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating cumulative sum</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-cumulative-sum/m-p/831436#M328548</link>
      <description>&lt;P&gt;Perhaps your issue is you created a CHARACTER visit variable with left aligned digit strings so that 10 sorts before 2 and 9.&lt;/P&gt;
&lt;P&gt;Either right align the values so they sort properly or convert them into a number.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data step1;
  set have;
  visit = input(scan(_visit_,2, ' '),32.);
run;

proc sort data=step1;
  by id visit;
run;

data want;
  set step1;
  by id visit;
  if first.visit them cumm = value;
  else comm + value;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 01 Sep 2022 16:30:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-cumulative-sum/m-p/831436#M328548</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-09-01T16:30:15Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating cumulative sum</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-cumulative-sum/m-p/831439#M328549</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you so much. It works.&lt;/P&gt;
&lt;P&gt;I need just to add something at level of Proc transpose .&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to cycle_1 ......cycle_10 .... rather than _1, 2_ ........_10&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ndamo_0-1662051772790.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/74936iF07E5636346C74C1/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ndamo_0-1662051772790.png" alt="ndamo_0-1662051772790.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Again , thank you &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Sep 2022 17:05:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-cumulative-sum/m-p/831439#M328549</guid>
      <dc:creator>ndamo</dc:creator>
      <dc:date>2022-09-01T17:05:03Z</dc:date>
    </item>
  </channel>
</rss>

