<?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: vertical sum in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/vertical-sum/m-p/39889#M10302</link>
    <description>Hi Sukanya. &lt;BR /&gt;
&lt;BR /&gt;
It works like a charm, thank you. &lt;BR /&gt;
&lt;BR /&gt;
Since the number of "months" and "monthly_sum" varies between say 4-500 every time I run the code, do you have any idea on how to prepare the arrays to handle the different number of obs ? &lt;BR /&gt;
&lt;BR /&gt;
Something like:&lt;BR /&gt;
array m{*} month1-month* &lt;BR /&gt;
array s{*} (dim) &lt;BR /&gt;
&lt;BR /&gt;
do i=1 to dim(m)</description>
    <pubDate>Wed, 03 Jun 2009 08:06:54 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2009-06-03T08:06:54Z</dc:date>
    <item>
      <title>vertical sum</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/vertical-sum/m-p/39887#M10300</link>
      <description>Hi guys. I'm quite new to SAS, hope you can help.&lt;BR /&gt;
&lt;BR /&gt;
I have this data set:&lt;BR /&gt;
&lt;BR /&gt;
data i;&lt;BR /&gt;
input month monthly_sum month1 month2 month3 month4 month5;&lt;BR /&gt;
cards;&lt;BR /&gt;
1 10 1 1 1 1 1 &lt;BR /&gt;
2 20 2 2 2 2 .&lt;BR /&gt;
3 30 3 3 3 . .&lt;BR /&gt;
4 40 4 4 . . . &lt;BR /&gt;
5 50 5 . . . .&lt;BR /&gt;
6 60  . . . . . &lt;BR /&gt;
;&lt;BR /&gt;
&lt;BR /&gt;
What I want to do is create a new variable that calculates the vertical sum of all month1-month5 variables individually and then divides that sum with total vertical sum of variable monthly_sum. But - the number of obs included in the calculation (vertically) is 1 less for each column, and it starts off 1 less each time (in this example 5 and not 6 obs) &lt;BR /&gt;
&lt;BR /&gt;
Like this:&lt;BR /&gt;
Ex. sum of month1=15&lt;BR /&gt;
sum of monthly_sum=150. &lt;BR /&gt;
new variable (15/100) =0,1&lt;BR /&gt;
&lt;BR /&gt;
Ex. sum of month2=10&lt;BR /&gt;
sum of monthly_sum=100. &lt;BR /&gt;
new variable (10/100)=0,1&lt;BR /&gt;
&lt;BR /&gt;
Ex. sum of month3=6&lt;BR /&gt;
sum of monthly_sum=60. &lt;BR /&gt;
new variable (6/60) =0,1&lt;BR /&gt;
&lt;BR /&gt;
Problem here is there will be different no of obs all the time, varying from 4 up to 2000.</description>
      <pubDate>Tue, 02 Jun 2009 14:36:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/vertical-sum/m-p/39887#M10300</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-06-02T14:36:57Z</dc:date>
    </item>
    <item>
      <title>Re: vertical sum</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/vertical-sum/m-p/39888#M10301</link>
      <description>One way of acheive this by using arrays. NEW{I} is the variable you want at the end...run it let me know if it doesn't work.&lt;BR /&gt;
&lt;BR /&gt;
 data j;&lt;BR /&gt;
  set i nobs=n;&lt;BR /&gt;
  array m{5} month1-month5;&lt;BR /&gt;
  array s{5} (0,0,0,0,0);&lt;BR /&gt;
  array sum1{5} (0,0,0,0,0);&lt;BR /&gt;
  array new{5};&lt;BR /&gt;
  do i=1 to 5;&lt;BR /&gt;
     s{i}=sum(s{i},m{i});  &lt;BR /&gt;
     if _n_ le n-i then  sum1{i}=sum(sum1{i},monthly_sum);&lt;BR /&gt;
     new{i}=s{i}/sum1{i};&lt;BR /&gt;
  end;&lt;BR /&gt;
  put _all_;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
~ Sukanya E</description>
      <pubDate>Tue, 02 Jun 2009 16:55:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/vertical-sum/m-p/39888#M10301</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-06-02T16:55:42Z</dc:date>
    </item>
    <item>
      <title>Re: vertical sum</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/vertical-sum/m-p/39889#M10302</link>
      <description>Hi Sukanya. &lt;BR /&gt;
&lt;BR /&gt;
It works like a charm, thank you. &lt;BR /&gt;
&lt;BR /&gt;
Since the number of "months" and "monthly_sum" varies between say 4-500 every time I run the code, do you have any idea on how to prepare the arrays to handle the different number of obs ? &lt;BR /&gt;
&lt;BR /&gt;
Something like:&lt;BR /&gt;
array m{*} month1-month* &lt;BR /&gt;
array s{*} (dim) &lt;BR /&gt;
&lt;BR /&gt;
do i=1 to dim(m)</description>
      <pubDate>Wed, 03 Jun 2009 08:06:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/vertical-sum/m-p/39889#M10302</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-06-03T08:06:54Z</dc:date>
    </item>
    <item>
      <title>Re: vertical sum</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/vertical-sum/m-p/39890#M10303</link>
      <description>No worries, Sukanya. &lt;BR /&gt;
I solved it with a call, &lt;BR /&gt;
&lt;BR /&gt;
(original code) &lt;BR /&gt;
data call;&lt;BR /&gt;
set max;&lt;BR /&gt;
call symput ('n', put(no, 2.));&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
And the array:&lt;BR /&gt;
data w_avg;&lt;BR /&gt;
set prepare nobs=n; &lt;BR /&gt;
format new1-new&amp;amp;n NUMX12.4;&lt;BR /&gt;
array m{&amp;amp;n} monthsonbooks1-monthsonbooks&amp;amp;n;&lt;BR /&gt;
array s{&amp;amp;n} (0-&amp;amp;n);&lt;BR /&gt;
array sum1{&amp;amp;n} (0-&amp;amp;n);&lt;BR /&gt;
array new{&amp;amp;n};&lt;BR /&gt;
do i=1 to &amp;amp;n;&lt;BR /&gt;
s{i}=sum(s{i},m{i}); &lt;BR /&gt;
if _n_ le n-i then sum1{i}=sum(sum1{i},ORIGLMT_Sum);&lt;BR /&gt;
new{i}=s{i}/sum1{i};&lt;BR /&gt;
end;&lt;BR /&gt;
put _all_;&lt;BR /&gt;
run;</description>
      <pubDate>Wed, 03 Jun 2009 10:43:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/vertical-sum/m-p/39890#M10303</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-06-03T10:43:44Z</dc:date>
    </item>
  </channel>
</rss>

