<?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: Sum based on column name and number in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Sum-based-on-column-name-and-number/m-p/593862#M170522</link>
    <description>&lt;P&gt;Not sure I get what you are trying to do, but shouldn't columns that represent dates before the starting date just by missing? In which case why not just sum ALL of the columns and ignore the value of the starting date.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How many numeric variables do you have? Make sure to count DATE variables since SAS stores dates as numbers.&lt;BR /&gt;How many of them need to contribute to the SUM?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  set have;
  sum=sum(of _numeric_) - sum(of account_open_date sum);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 03 Oct 2019 19:21:05 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2019-10-03T19:21:05Z</dc:date>
    <item>
      <title>Sum based on column name and number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-based-on-column-name-and-number/m-p/593842#M170505</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have data as below.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Depending on the Month of account opening, I need to create new variable called Required_Sum as Opening Balance + sum of individual months greater than opening month&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Desired is&amp;nbsp; :&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;For Cid=1 Account is opened in April month so Required_sum=opening_Balance_may19 + Balance_May19+ Balance_June19.... till end -----------&amp;gt;&amp;nbsp; Required_Sum =300+400 +200+150+80 = 1130&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;For Cid=2 Required_Sum=100+100+40+60=300&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Cid&lt;/TD&gt;&lt;TD&gt;Account_open_date&lt;/TD&gt;&lt;TD&gt;opening_Balance_apr19&lt;/TD&gt;&lt;TD&gt;Balance_apr19&lt;/TD&gt;&lt;TD&gt;Opening_balance_may19&lt;/TD&gt;&lt;TD&gt;Balance_may19&lt;/TD&gt;&lt;TD&gt;Opening_balance_jun19&lt;/TD&gt;&lt;TD&gt;Balance_jun19&lt;/TD&gt;&lt;TD&gt;Opening_balance_jul19&lt;/TD&gt;&lt;TD&gt;Balance_jul19&lt;/TD&gt;&lt;TD&gt;Opening_balance_aug19&lt;/TD&gt;&lt;TD&gt;Balance_aug19&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;08-May-19&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;300&lt;/TD&gt;&lt;TD&gt;400&lt;/TD&gt;&lt;TD&gt;100&lt;/TD&gt;&lt;TD&gt;200&lt;/TD&gt;&lt;TD&gt;100&lt;/TD&gt;&lt;TD&gt;150&lt;/TD&gt;&lt;TD&gt;170&lt;/TD&gt;&lt;TD&gt;80&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;13-Jun-19&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;100&lt;/TD&gt;&lt;TD&gt;100&lt;/TD&gt;&lt;TD&gt;100&lt;/TD&gt;&lt;TD&gt;40&lt;/TD&gt;&lt;TD&gt;100&lt;/TD&gt;&lt;TD&gt;60&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;16-Jul-19&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;150&lt;/TD&gt;&lt;TD&gt;100&lt;/TD&gt;&lt;TD&gt;100&lt;/TD&gt;&lt;TD&gt;100&lt;/TD&gt;&lt;TD&gt;100&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;\&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Above is just sample data and there are columns from Apr15 till Sep19. How do I run it through macro and get only the first month opening balance. Any help is really appreciated a lot&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Oct 2019 18:22:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-based-on-column-name-and-number/m-p/593842#M170505</guid>
      <dc:creator>Swapnil_21</dc:creator>
      <dc:date>2019-10-03T18:22:44Z</dc:date>
    </item>
    <item>
      <title>Re: Sum based on column name and number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-based-on-column-name-and-number/m-p/593854#M170516</link>
      <description>Are you required to maintain this data structure?&lt;BR /&gt;Did you create this table initially?&lt;BR /&gt;If you have your data in a long format it's easier to work with.</description>
      <pubDate>Thu, 03 Oct 2019 18:56:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-based-on-column-name-and-number/m-p/593854#M170516</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-10-03T18:56:35Z</dc:date>
    </item>
    <item>
      <title>Re: Sum based on column name and number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-based-on-column-name-and-number/m-p/593857#M170518</link>
      <description>Yes this table is required to be maintained. Every month 2 new columns are&lt;BR /&gt;added to this table.&lt;BR /&gt;</description>
      <pubDate>Thu, 03 Oct 2019 18:58:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-based-on-column-name-and-number/m-p/593857#M170518</guid>
      <dc:creator>Swapnil_21</dc:creator>
      <dc:date>2019-10-03T18:58:32Z</dc:date>
    </item>
    <item>
      <title>Re: Sum based on column name and number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-based-on-column-name-and-number/m-p/593862#M170522</link>
      <description>&lt;P&gt;Not sure I get what you are trying to do, but shouldn't columns that represent dates before the starting date just by missing? In which case why not just sum ALL of the columns and ignore the value of the starting date.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How many numeric variables do you have? Make sure to count DATE variables since SAS stores dates as numbers.&lt;BR /&gt;How many of them need to contribute to the SUM?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  set have;
  sum=sum(of _numeric_) - sum(of account_open_date sum);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Oct 2019 19:21:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-based-on-column-name-and-number/m-p/593862#M170522</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-10-03T19:21:05Z</dc:date>
    </item>
    <item>
      <title>Re: Sum based on column name and number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-based-on-column-name-and-number/m-p/593868#M170526</link>
      <description>Out of curiosity what would the sum of a 'balance' field represent from a business context?&lt;BR /&gt;&lt;BR /&gt;In general, I keep $1000 in my account as  balance. Not sure how the sum of that, $12,000 is a useful metric so I'm curious as to how this would be used...&lt;BR /&gt;&lt;BR /&gt;Balance typically means the outstanding amount as of a particular date, but I suppose it could have a different interpretation.</description>
      <pubDate>Thu, 03 Oct 2019 19:33:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-based-on-column-name-and-number/m-p/593868#M170526</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-10-03T19:33:53Z</dc:date>
    </item>
    <item>
      <title>Re: Sum based on column name and number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-based-on-column-name-and-number/m-p/594026#M170599</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292735"&gt;@Swapnil_21&lt;/a&gt;:&lt;/P&gt;
&lt;P&gt;First, tell whomever has designed this "data structure" and intends to keep and maintain it this way: "Welcome to data processing and maintenance nightmare".&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Having said that, you can do what you need this way:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;                                                                                                                                                                                                                                                     
  input Cid                                                                                                                                                                                                                                                     
        Account_open_date :date.                                                                                                                                                                                                                                
        opening_Balance_apr19                                                                                                                                                                                                                                   
        Balance_apr19                                                                                                                                                                                                                                           
        Opening_balance_may19                                                                                                                                                                                                                                   
        Balance_may19                                                                                                                                                                                                                                           
        Opening_balance_jun19                                                                                                                                                                                                                                   
        Balance_jun19                                                                                                                                                                                                                                           
        Opening_balance_jul19                                                                                                                                                                                                                                   
        Balance_jul19                                                                                                                                                                                                                                           
        Opening_balance_aug19                                                                                                                                                                                                                                   
        Balance_aug19                                                                                                                                                                                                                                           
  ;                                                                                                                                                                                                                                                             
  format Account_open_date yymmdd10. ;                                                                                                                                                                                                                          
  cards ;                                                                                                                                                                                                                                                       
1  08-May-19  .  .  300  400  100  200  100  150  170   80                                                                                                                                                                                                      
2  13-Jun-19  .  .    .    .  100  100  100   40  100   60                                                                                                                                                                                                      
2  16-Jul-19  .  .    .    .    .  150  100  100  100  100                                                                                                                                                                                                      
;                                                                                                                                                                                                                                                               
run ;                                                                                                                                                                                                                                                           
                                                                                                                                                                                                                                                                
data want (drop = _:) ;                                                                                                                                                                                                                                         
  set have ;                                                                                                                                                                                                                                                    
  array nn _numeric_ ;                                                                                                                                                                                                                                          
  do over nn ;                                                                                                                                                                                                                                                  
    if cmiss (nn) then continue ;                                                                                                                                                                                                                               
    _open = lowcase (vname (nn)) =: "opening_balance" ;                                                                                                                                                                                                         
    _seq = sum (_seq, _open) ;                                                                                                                                                                                                                                  
    if _seq = 1 or (_seq and not _open) then Required_Sum = sum (required_sum, nn) ;                                                                                                                                                                            
  end ;                                                                                                                                                                                                                                                         
run ;                              
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Paul D.&lt;/P&gt;</description>
      <pubDate>Fri, 04 Oct 2019 03:46:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-based-on-column-name-and-number/m-p/594026#M170599</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2019-10-04T03:46:30Z</dc:date>
    </item>
  </channel>
</rss>

