<?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: Creating a cumulative column in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-cumulative-column/m-p/812328#M320501</link>
    <description>&lt;P&gt;Why not SQL with sum(COST) and group by MONTH, SEG ?&lt;/P&gt;</description>
    <pubDate>Tue, 10 May 2022 08:52:03 GMT</pubDate>
    <dc:creator>ChrisNZ</dc:creator>
    <dc:date>2022-05-10T08:52:03Z</dc:date>
    <item>
      <title>Creating a cumulative column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-cumulative-column/m-p/812319#M320499</link>
      <description>&lt;P&gt;Hello, I would like to create a cumulative column in relation to the time variable "month".&lt;/P&gt;
&lt;P&gt;Thanks for your help&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 480pt;" border="0" width="640" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD width="80" height="19" style="height: 14.5pt; width: 60pt;"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="80" style="width: 60pt;"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="80" style="width: 60pt;"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="80" style="width: 60pt;"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="80" style="width: 60pt;"&gt;&lt;STRONG&gt;Want:&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="80" style="width: 60pt;"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="80" style="width: 60pt;"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="80" style="width: 60pt;"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD height="19" class="xl65" style="height: 14.5pt;"&gt;Month&lt;/TD&gt;
&lt;TD class="xl65" style="border-left: none;"&gt;Seg&lt;/TD&gt;
&lt;TD class="xl65" style="border-left: none;"&gt;Cost&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD class="xl65"&gt;Month&lt;/TD&gt;
&lt;TD class="xl65" style="border-left: none;"&gt;Seg&lt;/TD&gt;
&lt;TD class="xl65" style="border-left: none;"&gt;Cumul Cost&lt;/TD&gt;
&lt;TD class="xl65" style="border-left: none;"&gt;Cost&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD height="19" align="right" class="xl65" style="height: 14.5pt; border-top: none;"&gt;202201&lt;/TD&gt;
&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;Up&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;5&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD align="right" class="xl66" style="border-top: none;"&gt;202201&lt;/TD&gt;
&lt;TD class="xl66" style="border-top: none; border-left: none;"&gt;Up&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;49&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;49&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD height="19" align="right" class="xl65" style="height: 14.5pt; border-top: none;"&gt;202201&lt;/TD&gt;
&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;Down&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;10&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD align="right" class="xl66" style="border-top: none;"&gt;202201&lt;/TD&gt;
&lt;TD class="xl66" style="border-top: none; border-left: none;"&gt;Down&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;109&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;109&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD height="19" align="right" class="xl65" style="height: 14.5pt; border-top: none;"&gt;202202&lt;/TD&gt;
&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;Up&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;33&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD align="right" class="xl66" style="border-top: none;"&gt;202201&lt;/TD&gt;
&lt;TD class="xl66" style="border-top: none; border-left: none;"&gt;Right&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;44&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;44&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD height="19" align="right" class="xl65" style="height: 14.5pt; border-top: none;"&gt;202202&lt;/TD&gt;
&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;Left&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;66&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD align="right" class="xl66" style="border-top: none;"&gt;202201&lt;/TD&gt;
&lt;TD class="xl66" style="border-top: none; border-left: none;"&gt;left&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;33&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;33&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD height="19" align="right" class="xl65" style="height: 14.5pt; border-top: none;"&gt;202201&lt;/TD&gt;
&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;Right&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;44&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none;"&gt;202202&lt;/TD&gt;
&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;Up&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;115&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;66&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD height="19" align="right" class="xl65" style="height: 14.5pt; border-top: none;"&gt;202201&lt;/TD&gt;
&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;left&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;22&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none;"&gt;202202&lt;/TD&gt;
&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;Down&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;109&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD height="19" align="right" class="xl65" style="height: 14.5pt; border-top: none;"&gt;202203&lt;/TD&gt;
&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;left&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;66&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none;"&gt;202202&lt;/TD&gt;
&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;Right&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;44&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD height="19" align="right" class="xl65" style="height: 14.5pt; border-top: none;"&gt;202203&lt;/TD&gt;
&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;right&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;88&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none;"&gt;202202&lt;/TD&gt;
&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;Left&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;99&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;66&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD height="19" align="right" class="xl65" style="height: 14.5pt; border-top: none;"&gt;202201&lt;/TD&gt;
&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;Up&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;44&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD align="right" class="xl66" style="border-top: none;"&gt;202203&lt;/TD&gt;
&lt;TD class="xl66" style="border-top: none; border-left: none;"&gt;Up&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;115&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD height="19" align="right" class="xl65" style="height: 14.5pt; border-top: none;"&gt;202201&lt;/TD&gt;
&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;Down&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;99&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD align="right" class="xl66" style="border-top: none;"&gt;202203&lt;/TD&gt;
&lt;TD class="xl66" style="border-top: none; border-left: none;"&gt;Down&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;109&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD height="19" align="right" class="xl65" style="height: 14.5pt; border-top: none;"&gt;202202&lt;/TD&gt;
&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;Up&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;33&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD align="right" class="xl66" style="border-top: none;"&gt;202203&lt;/TD&gt;
&lt;TD class="xl66" style="border-top: none; border-left: none;"&gt;Right&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;143&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;99&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD height="19" align="right" class="xl65" style="height: 14.5pt; border-top: none;"&gt;202201&lt;/TD&gt;
&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;left&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;11&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD align="right" class="xl66" style="border-top: none;"&gt;202203&lt;/TD&gt;
&lt;TD class="xl66" style="border-top: none; border-left: none;"&gt;Left&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;264&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;165&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD height="19" align="right" class="xl65" style="height: 14.5pt; border-top: none;"&gt;202203&lt;/TD&gt;
&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;left&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;99&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD height="19" align="right" class="xl65" style="height: 14.5pt; border-top: none;"&gt;202203&lt;/TD&gt;
&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;right&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;11&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Tue, 10 May 2022 08:15:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-cumulative-column/m-p/812319#M320499</guid>
      <dc:creator>WilliamB</dc:creator>
      <dc:date>2022-05-10T08:15:47Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a cumulative column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-cumulative-column/m-p/812328#M320501</link>
      <description>&lt;P&gt;Why not SQL with sum(COST) and group by MONTH, SEG ?&lt;/P&gt;</description>
      <pubDate>Tue, 10 May 2022 08:52:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-cumulative-column/m-p/812328#M320501</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2022-05-10T08:52:03Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a cumulative column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-cumulative-column/m-p/812372#M320525</link>
      <description>&lt;P&gt;Please add some details explaining the logic you want applied and post the data in usable form.&lt;/P&gt;</description>
      <pubDate>Tue, 10 May 2022 12:01:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-cumulative-column/m-p/812372#M320525</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2022-05-10T12:01:42Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a cumulative column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-cumulative-column/m-p/812499#M320588</link>
      <description>&lt;P&gt;Here's one way to address the problem.&amp;nbsp; Note that this is untested code, so you will have to try it to see if it works.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
   array cums {202201:202203, 4} _temporary_ (0 0 0 0 0 0 0 0 0 0 0 0);
   set have end=done;
   select (upcase(seg));
      when ('UP')  col=1;
      when ('DOWN')  col=2;
      when ('RIGHT')  col=3;
      when ('LEFT')  col=4;
   end;
   cums{month, col} + cost;
   if done;
   do month = 202201 to 202203;
      cum_cost = 0;
      do col = 1 to 4;
         cost = cums{month, col};
         cum_cost + cost;
         select {col};
             when (1) seg='Up';
             when (2) seg='Down';
             when (3) seg='Right';
             when (4) seg='Left';
         end;
         output;
      end;
   end;
   drop   col;
run;
proc print;
run; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;For future reference, note that "right" and "Right" are different in most any programming language.&amp;nbsp; I made reasonable assumptions about what the output should contain.&amp;nbsp; And if you have any values that are misspelled (such as "Rigt") the program will end with an error.&lt;/P&gt;</description>
      <pubDate>Tue, 10 May 2022 21:25:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-cumulative-column/m-p/812499#M320588</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2022-05-10T21:25:05Z</dc:date>
    </item>
  </channel>
</rss>

