<?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 Sum observations looping on the variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Sum-observations-looping-on-the-variables/m-p/262901#M51425</link>
    <description>&lt;P&gt;Dear Experts,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am in the following situation (attached file):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have several produts (row) and and different variables corresponding to different monthly date, e.g. XX_201501, XX_201502, XX_201503... XX_201610 (progressiv date).&lt;/P&gt;&lt;P&gt;How can I sum by row from 201503 to 201506? Thanks and best regards.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 11 Apr 2016 13:44:10 GMT</pubDate>
    <dc:creator>Sir_Highbury</dc:creator>
    <dc:date>2016-04-11T13:44:10Z</dc:date>
    <item>
      <title>Sum observations looping on the variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-observations-looping-on-the-variables/m-p/262901#M51425</link>
      <description>&lt;P&gt;Dear Experts,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am in the following situation (attached file):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have several produts (row) and and different variables corresponding to different monthly date, e.g. XX_201501, XX_201502, XX_201503... XX_201610 (progressiv date).&lt;/P&gt;&lt;P&gt;How can I sum by row from 201503 to 201506? Thanks and best regards.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Apr 2016 13:44:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-observations-looping-on-the-variables/m-p/262901#M51425</guid>
      <dc:creator>Sir_Highbury</dc:creator>
      <dc:date>2016-04-11T13:44:10Z</dc:date>
    </item>
    <item>
      <title>Re: Sum observations looping on the variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-observations-looping-on-the-variables/m-p/262905#M51426</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To get tested code, its a good idea to post test data in the form of a datastep in the post - Excel files are a dangerous download and a pain to deal with at any point.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My first suggestion would be to normalise your data, unless you are creating a report - i.e. at the proc report stage, you will find your programming is a lot easy to write and maintain if your data is long, rather than wide. &amp;nbsp;For instance this problem would become a simple select sum() from have where date between "20150301"d and "20150601"d. &amp;nbsp;To do the same thing in this data structure you need to put in arrays, and this doesn't carry over differet steps. &amp;nbsp;The syntax is (untested due to the above):&lt;/P&gt;
&lt;PRE&gt;data want;
  set have;
  array dts{8} 201501--201508;  /* Note I use the shorthand --, all variables between */
  result=0;
  do i=3 to 7;
     result=sum(results,dts{i});
  end;
run;
&lt;/PRE&gt;</description>
      <pubDate>Mon, 11 Apr 2016 13:45:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-observations-looping-on-the-variables/m-p/262905#M51426</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-04-11T13:45:33Z</dc:date>
    </item>
    <item>
      <title>Re: Sum observations looping on the variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-observations-looping-on-the-variables/m-p/262908#M51427</link>
      <description>&lt;P&gt;dear RW9,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks for the suggestions and the prompt reply. I also thought using the proc transpose, but the output I should generate is exactly as the input, just aggregating some monthts on the base of the sales period. Can I do the calculation sticking to the same structure (just having one more column with the sum).&lt;/P&gt;&lt;P&gt;Thanks again.&lt;/P&gt;</description>
      <pubDate>Mon, 11 Apr 2016 13:57:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-observations-looping-on-the-variables/m-p/262908#M51427</guid>
      <dc:creator>Sir_Highbury</dc:creator>
      <dc:date>2016-04-11T13:57:21Z</dc:date>
    </item>
    <item>
      <title>Re: Sum observations looping on the variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-observations-looping-on-the-variables/m-p/262913#M51429</link>
      <description>&lt;P&gt;&amp;nbsp;The code I gave should be a good starting point:&lt;/P&gt;
&lt;PRE&gt;data want;
  set have;
  array dts{8} 201501--201508;  /* Note I use the shorthand --, all variables between */
  result=0;
  do i=3 to 7;
     result=sum(results,dts{i});
  end;
run;&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Basically you set and array reference to your variables, then loop over then. &amp;nbsp;Or you could just do it directly:&lt;/P&gt;
&lt;PRE&gt;data want;
  set have;
  result=sum(201503,201504,201505,201506);
run;&lt;/PRE&gt;</description>
      <pubDate>Mon, 11 Apr 2016 14:14:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-observations-looping-on-the-variables/m-p/262913#M51429</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-04-11T14:14:11Z</dc:date>
    </item>
    <item>
      <title>Re: Sum observations looping on the variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-observations-looping-on-the-variables/m-p/262915#M51430</link>
      <description>&lt;P&gt;data top_6;&lt;BR /&gt;set Perm.Summary_sales;&lt;BR /&gt;test=sum(xx_200906--xx_200909);&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;it seems to be also ok.... or? Thanks for the hint (--)&lt;/P&gt;</description>
      <pubDate>Mon, 11 Apr 2016 14:24:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-observations-looping-on-the-variables/m-p/262915#M51430</guid>
      <dc:creator>Sir_Highbury</dc:creator>
      <dc:date>2016-04-11T14:24:12Z</dc:date>
    </item>
    <item>
      <title>Re: Sum observations looping on the variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-observations-looping-on-the-variables/m-p/262918#M51431</link>
      <description>&lt;P&gt;Usually you should use the keyword OF in the sum function if you're using a list of variables&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ie. &amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;sum(OFStart_var--end_var)&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 11 Apr 2016 14:36:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-observations-looping-on-the-variables/m-p/262918#M51431</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-04-11T14:36:08Z</dc:date>
    </item>
  </channel>
</rss>

