<?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: Issue with picking the final result of cumulative average and then using it for further computat in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Issue-with-picking-the-final-result-of-cumulative-average-and/m-p/328891#M73501</link>
    <description>&lt;P&gt;Your question is relatively clear, thanks for posting for sample data and the code you have so far!&lt;/P&gt;
&lt;P&gt;A+ &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, here's how to do what you want, though I'm not sure what your array is trying to do. I think you're trying to calculate the percent of total, so I'm going with that. If not, please clarify.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one;
input name$ sal;
datalines;
A 100
B 200
C 300
D 400
E 500
;
run;

proc means data=one noprint nway;
output out=tot_val sum(sal)=tot_sal;
run;

data two;
set one;
if _n_ = 1 then set tot_val (drop = _type_ _freq_);
percent = sal/tot_sal;
format percent percent12.1;
run;

proc print data=two;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And an alternative method, if I guessed correctly:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*Another way without the multiple steps;
proc freq data=one;
table name/out=three outcum outpct;
weight sal;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 31 Jan 2017 21:40:50 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2017-01-31T21:40:50Z</dc:date>
    <item>
      <title>Issue with picking the final result of cumulative average and then using it for further computation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issue-with-picking-the-final-result-of-cumulative-average-and/m-p/328884#M73498</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a base dataset on which I am performing computation as:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data one;&lt;BR /&gt;input name$ sal;&lt;BR /&gt;datalines;&lt;BR /&gt;A 100&lt;BR /&gt;B 200&lt;BR /&gt;C 300&lt;BR /&gt;D 400&lt;BR /&gt;E 500&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now, I want to calculate as:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data two;&lt;BR /&gt;set one;&lt;BR /&gt;array x(*) sal;&lt;BR /&gt;do i = 1 to dim(x);&lt;BR /&gt;mypercentage = x{i}*100/[CUMULATIVE TOTAL OF SAL FROM DATASET ONE];&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;BR /&gt;proc print;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My issue is: I am able to run this dataset two and getting proper result if I am putting 2( just a random number) instead of the CUMULATIVE TOTAL OF SAL FROM DATASET ONE.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to use the cumulative total of sal from dataset one and use it in dataset two which will tell like 100 is 6.66 percent of 1500 (cumulative total of sal from dataset one) and so on for every iteration.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please suggest, how is it possible. I hope, I am clear with my question.&lt;/P&gt;</description>
      <pubDate>Tue, 31 Jan 2017 21:22:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issue-with-picking-the-final-result-of-cumulative-average-and/m-p/328884#M73498</guid>
      <dc:creator>GurmeetKaur_23</dc:creator>
      <dc:date>2017-01-31T21:22:44Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with picking the final result of cumulative average and then using it for further computat</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issue-with-picking-the-final-result-of-cumulative-average-and/m-p/328891#M73501</link>
      <description>&lt;P&gt;Your question is relatively clear, thanks for posting for sample data and the code you have so far!&lt;/P&gt;
&lt;P&gt;A+ &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, here's how to do what you want, though I'm not sure what your array is trying to do. I think you're trying to calculate the percent of total, so I'm going with that. If not, please clarify.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one;
input name$ sal;
datalines;
A 100
B 200
C 300
D 400
E 500
;
run;

proc means data=one noprint nway;
output out=tot_val sum(sal)=tot_sal;
run;

data two;
set one;
if _n_ = 1 then set tot_val (drop = _type_ _freq_);
percent = sal/tot_sal;
format percent percent12.1;
run;

proc print data=two;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And an alternative method, if I guessed correctly:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*Another way without the multiple steps;
proc freq data=one;
table name/out=three outcum outpct;
weight sal;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 31 Jan 2017 21:40:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issue-with-picking-the-final-result-of-cumulative-average-and/m-p/328891#M73501</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-01-31T21:40:50Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with picking the final result of cumulative average and then using it for further computat</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issue-with-picking-the-final-result-of-cumulative-average-and/m-p/328895#M73503</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Hi There,&lt;/SPAN&gt;&lt;/P&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Thanks for reply &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; but I want something that I have shown in the excel sheet and that too using arrays.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Can you help me resolve that issue via using arrays please?&lt;/DIV&gt;&lt;BR /&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/13385i723544B591B66753/image-size/large?v=1.0&amp;amp;px=600" border="0" alt="How I want the output.PNG" title="How I want the output.PNG" /&gt;</description>
      <pubDate>Tue, 31 Jan 2017 21:54:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issue-with-picking-the-final-result-of-cumulative-average-and/m-p/328895#M73503</guid>
      <dc:creator>GurmeetKaur_23</dc:creator>
      <dc:date>2017-01-31T21:54:27Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with picking the final result of cumulative average and then using it for further computat</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issue-with-picking-the-final-result-of-cumulative-average-and/m-p/328896#M73504</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/117781"&gt;@GurmeetKaur_23&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;&lt;SPAN&gt;Hi There,&lt;/SPAN&gt;&lt;/P&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;Can you help me resolve that issue via using arrays please?&lt;/DIV&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The results are similar to what you have in Excel, which part of the code/results&amp;nbsp;suggested doesn't work for what you want?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;No, you can't use arrays. In SAS arrays work on a single row, not on columns. They're considered a shortcut reference to variables but not an array in the sense of matrix/arrays. If you really want to use arrays, you'll need to use IML and matrix language.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 31 Jan 2017 21:56:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issue-with-picking-the-final-result-of-cumulative-average-and/m-p/328896#M73504</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-01-31T21:56:55Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with picking the final result of cumulative average and then using it for further computat</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issue-with-picking-the-final-result-of-cumulative-average-and/m-p/328932#M73515</link>
      <description>&lt;P&gt;You might want a report procedure as the kind of percentages you are using can lead to confusion when used as input into other processes.&lt;/P&gt;
&lt;P&gt;Please look at&lt;/P&gt;
&lt;PRE&gt;proc tabulate data=one;
   class name;
   var sal;
   table name all=total,
         sal*(sum='Sal total' colpctsum="Percent of column total");
run;&lt;/PRE&gt;</description>
      <pubDate>Tue, 31 Jan 2017 23:37:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issue-with-picking-the-final-result-of-cumulative-average-and/m-p/328932#M73515</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-01-31T23:37:55Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with picking the final result of cumulative average and then using it for further computat</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issue-with-picking-the-final-result-of-cumulative-average-and/m-p/329041#M73555</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;SPAN&gt;ballardw. Thanks a lot for helping me with the fact that "No, you can't use arrays. In SAS arrays work on a single row, not on columns. They're considered a shortcut reference to variables but not an array in the sense of matrix/arrays. If you really want to use arrays, you'll need to use IML and matrix language.&amp;nbsp;"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Also, the solution that you gave is working as expected. Really, thanks a lot.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Feb 2017 11:22:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issue-with-picking-the-final-result-of-cumulative-average-and/m-p/329041#M73555</guid>
      <dc:creator>GurmeetKaur_23</dc:creator>
      <dc:date>2017-02-01T11:22:28Z</dc:date>
    </item>
  </channel>
</rss>

