<?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 YTD information using sum in arrays in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/YTD-information-using-sum-in-arrays/m-p/534015#M32998</link>
    <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have one ID column and twelve others columns that have monthly information of profit before taxes, which i will call here as PBT. My aim is to create twelve new columns with the year to date information of PBT, which means ((cumulated information up to intended date)/(number of months up to intended date))*12, all this in on single file. I already did this in different files using ARRAY through the code below within a MACRO statement:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA CUM_PBT_&amp;amp;MONTH. (DROP=i);&lt;BR /&gt;SET PBT_2018;&lt;BR /&gt;FORMAT PBT_YTD_&amp;amp;MONTH. COMMA19.2;&lt;BR /&gt;ARRAY PBT[*] '201801'n-"&amp;amp;MONTH."n;&lt;BR /&gt;DO i=1 to 12;&lt;BR /&gt;PBT_YTD_&amp;amp;MES.=(SUM(of '201801'n-"&amp;amp;MES."n)/DIM(BAI))*12;&lt;BR /&gt;END;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How could I provide this code to have all these columns in a same file ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To illustrate better what I want I attached a file that i did my objective (beggining at column 'O') information using excel from the original information (from column B to M).&lt;/P&gt;</description>
    <pubDate>Fri, 08 Feb 2019 17:29:48 GMT</pubDate>
    <dc:creator>claudiopcjr</dc:creator>
    <dc:date>2019-02-08T17:29:48Z</dc:date>
    <item>
      <title>YTD information using sum in arrays</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/YTD-information-using-sum-in-arrays/m-p/534015#M32998</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have one ID column and twelve others columns that have monthly information of profit before taxes, which i will call here as PBT. My aim is to create twelve new columns with the year to date information of PBT, which means ((cumulated information up to intended date)/(number of months up to intended date))*12, all this in on single file. I already did this in different files using ARRAY through the code below within a MACRO statement:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA CUM_PBT_&amp;amp;MONTH. (DROP=i);&lt;BR /&gt;SET PBT_2018;&lt;BR /&gt;FORMAT PBT_YTD_&amp;amp;MONTH. COMMA19.2;&lt;BR /&gt;ARRAY PBT[*] '201801'n-"&amp;amp;MONTH."n;&lt;BR /&gt;DO i=1 to 12;&lt;BR /&gt;PBT_YTD_&amp;amp;MES.=(SUM(of '201801'n-"&amp;amp;MES."n)/DIM(BAI))*12;&lt;BR /&gt;END;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How could I provide this code to have all these columns in a same file ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To illustrate better what I want I attached a file that i did my objective (beggining at column 'O') information using excel from the original information (from column B to M).&lt;/P&gt;</description>
      <pubDate>Fri, 08 Feb 2019 17:29:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/YTD-information-using-sum-in-arrays/m-p/534015#M32998</guid>
      <dc:creator>claudiopcjr</dc:creator>
      <dc:date>2019-02-08T17:29:48Z</dc:date>
    </item>
    <item>
      <title>Re: YTD information using sum in arrays</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/YTD-information-using-sum-in-arrays/m-p/534016#M32999</link>
      <description>&lt;P&gt;Providing code with macro variables and no idea what those macro variables may hold obscures the objective. Where does "&amp;amp;month" come from, what values does it take? Same for "&amp;amp;Mes".&lt;/P&gt;
&lt;P&gt;Does the ID variable play any role in the calculations involved?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One suspects you are forcing an "Excel like" approach to the solution. It may be that your source data would be better off transformed into a long form with ID Month (as an actual date value) and "value".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you provide an example of what "have all these columns in a same file&amp;nbsp;" would look like.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You will getter better responses if the example data is provided in the form of a data step so we can test code against it. Instructions here: &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt; will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.&lt;/P&gt;</description>
      <pubDate>Fri, 08 Feb 2019 17:39:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/YTD-information-using-sum-in-arrays/m-p/534016#M32999</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-02-08T17:39:36Z</dc:date>
    </item>
    <item>
      <title>Re: YTD information using sum in arrays</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/YTD-information-using-sum-in-arrays/m-p/534024#M33000</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is this what your trying to,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id $ val1 val2 val3 val4;
datalines;
A 1 2 3 4
B 2 4 5 6
C 3 4 5 6
;
run;

options symbolgen mprint mlogic;
%Macro test();

data want;
set have;
array val{4} val1-val4;
array PBT_Val{4} PBT_Val1-PBT_Val4;
%do i=1 %to 4;
PBT_Val(&amp;amp;i.)=(sum(of val1-val&amp;amp;i.)/&amp;amp;i)*12;
%end;
run;

%mend test;
%test;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 08 Feb 2019 18:18:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/YTD-information-using-sum-in-arrays/m-p/534024#M33000</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2019-02-08T18:18:20Z</dc:date>
    </item>
    <item>
      <title>Re: YTD information using sum in arrays</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/YTD-information-using-sum-in-arrays/m-p/534458#M33023</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/83078"&gt;@SuryaKiran&lt;/a&gt; for your answer, the code ran succesfully on the way that you wrote. Unfortunatelly the result didn't come out as expected, I believe it's because the variables specified on the terms:&amp;nbsp;%do i=01 %to 12;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As you can check on the file that I attached there are 12 columns, one for each month, and the code doesn't seem recognizing the correct name of the months from 201802 till 201809. Is there a way to preserve the 0 on the left of number ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's the code that I ran:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;options symbolgen mprint mlogic;&lt;BR /&gt;%Macro test();&lt;/P&gt;&lt;P&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;array val{*} '201801'n-'201812'n;&lt;BR /&gt;array PBT_Val{*} PBT_201801-PBT_201812;&lt;BR /&gt;%do i=01 %to 12;&lt;BR /&gt;PBT_Val(&amp;amp;i.)=(sum(of '201801'n-"2018&amp;amp;i."n)/&amp;amp;i)*12;&lt;BR /&gt;%end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;%mend test;&lt;BR /&gt;%test;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The results are on the attached file ("WANT.xlsx").&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Mon, 11 Feb 2019 13:59:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/YTD-information-using-sum-in-arrays/m-p/534458#M33023</guid>
      <dc:creator>claudiopcjr</dc:creator>
      <dc:date>2019-02-11T13:59:30Z</dc:date>
    </item>
    <item>
      <title>Re: YTD information using sum in arrays</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/YTD-information-using-sum-in-arrays/m-p/534525#M33026</link>
      <description>&lt;P&gt;You might find this easier if you got rid of the macro language entirely.&amp;nbsp; Let the DATA step process data instead.&amp;nbsp; For example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;data want;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;set have;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;array val{*} '201801'n-'201812'n;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;array PBT_Val{*} PBT_201801-PBT_201812;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;total=0;&lt;BR /&gt;&lt;SPAN&gt;do i=1 to 12;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;total + val{i};&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;PBT_Val(&amp;amp;i.)=total/i*12;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;end;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;drop total;&lt;BR /&gt;&lt;SPAN&gt;run;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Feb 2019 16:42:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/YTD-information-using-sum-in-arrays/m-p/534525#M33026</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-02-11T16:42:11Z</dc:date>
    </item>
    <item>
      <title>Re: YTD information using sum in arrays</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/YTD-information-using-sum-in-arrays/m-p/534534#M33028</link>
      <description>&lt;P&gt;It worked perfectly thank you very much.&lt;/P&gt;</description>
      <pubDate>Mon, 11 Feb 2019 17:07:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/YTD-information-using-sum-in-arrays/m-p/534534#M33028</guid>
      <dc:creator>claudiopcjr</dc:creator>
      <dc:date>2019-02-11T17:07:26Z</dc:date>
    </item>
  </channel>
</rss>

