<?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 all numeric variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Sum-all-numeric-variables/m-p/228248#M267921</link>
    <description>&lt;P&gt;What "trouble with variable names" can happen in this situation?&lt;/P&gt;</description>
    <pubDate>Fri, 02 Oct 2015 18:32:49 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2015-10-02T18:32:49Z</dc:date>
    <item>
      <title>Sum all numeric variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-all-numeric-variables/m-p/228238#M267918</link>
      <description>&lt;P&gt;My data looks like this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Obs&amp;nbsp;&amp;nbsp;&amp;nbsp;Id&amp;nbsp;&amp;nbsp; Numeric&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Character&lt;/P&gt;
&lt;P&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; xxx&lt;/P&gt;
&lt;P&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;xxx&lt;/P&gt;
&lt;P&gt;3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; xyz&lt;/P&gt;
&lt;P&gt;4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; xyz&lt;/P&gt;
&lt;P&gt;5&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 5&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; zzz&lt;/P&gt;
&lt;P&gt;6&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 6&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; zzz&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What I want to do is create a new table that is grouped by the ID variable, while summing the numeric variable and retaining the value of the character variable (which is the same for every ID).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I know how to do this for this exact example with proc sql, a select statement and summing Numeric, and using a group by statement, but the problem is there are hundreds of numeric variables in my actual data set and I want to do it for every one. Anyone have any ideas?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Fri, 02 Oct 2015 16:57:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-all-numeric-variables/m-p/228238#M267918</guid>
      <dc:creator>jacob_klimek</dc:creator>
      <dc:date>2015-10-02T16:57:28Z</dc:date>
    </item>
    <item>
      <title>Re: Sum all numeric variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-all-numeric-variables/m-p/228239#M267919</link>
      <description>&lt;P&gt;UNTESTED CODE&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=whatever;
    id character;
    class id;
    var _numeric_;
    output out=sums sum=;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 02 Oct 2015 17:04:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-all-numeric-variables/m-p/228239#M267919</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2015-10-02T17:04:26Z</dc:date>
    </item>
    <item>
      <title>Re: Sum all numeric variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-all-numeric-variables/m-p/228245#M267920</link>
      <description>&lt;P&gt;Use the AUTONAME option of &lt;STRONG&gt;proc summary&lt;/STRONG&gt; to avoid trouble with variable names&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
proc summary data=have;
    by id notsorted;
    id character;
    var _numeric_;
    output out=want( drop=id_sum _: ) sum= / autoname;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 02 Oct 2015 18:01:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-all-numeric-variables/m-p/228245#M267920</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2015-10-02T18:01:33Z</dc:date>
    </item>
    <item>
      <title>Re: Sum all numeric variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-all-numeric-variables/m-p/228248#M267921</link>
      <description>&lt;P&gt;What "trouble with variable names" can happen in this situation?&lt;/P&gt;</description>
      <pubDate>Fri, 02 Oct 2015 18:32:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-all-numeric-variables/m-p/228248#M267921</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2015-10-02T18:32:49Z</dc:date>
    </item>
    <item>
      <title>Re: Sum all numeric variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-all-numeric-variables/m-p/228265#M267922</link>
      <description>&lt;P&gt;When ID is being used as a class or by variable but is also a _numeric_, it ends up being twice in the output dataset. Proc Summary doesn't like that.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Oct 2015 19:15:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-all-numeric-variables/m-p/228265#M267922</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2015-10-02T19:15:26Z</dc:date>
    </item>
    <item>
      <title>Re: Sum all numeric variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-all-numeric-variables/m-p/228266#M267923</link>
      <description>This sums at the overall level plus the ID level, you may want to restrict it using the NWAY option to only the ID level.</description>
      <pubDate>Fri, 02 Oct 2015 19:15:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-all-numeric-variables/m-p/228266#M267923</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2015-10-02T19:15:30Z</dc:date>
    </item>
    <item>
      <title>Re: Sum all numeric variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-all-numeric-variables/m-p/228478#M267924</link>
      <description>&lt;P&gt;I am not sure which interpretation is correct, so I have included two versions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the objective is to&amp;nbsp;do running sums of each numeric variable (individually), grouped by ID, then in theory, something like this could work:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA have; 
   INPUT id Numeric1 Numeric2 Numeric3 Numeric4 Character $;
   DATALINES; 
1 1 11 115 1199 xxx
1 2 22 225 2299 xxx
2 3 33 335 3399 xyz
2 4 44 445 4499 xyz
3 5 55 555 5599 zzz
3 6 66 665 6699 zzz
;
RUN;


/* untested code */
DATA want;
  SET have;
  BY id; /* assumes your data is sorted properly */
  
  LENGTH Sum1-Sum4 8;
  ARRAY num_array Numeric1-Numeric4;
  ARRAY sum_array Sum1-Sum4;

  DO OVER num_array;
    IF first.id THEN sum_array = num_array;
    ELSE             sum_array + num_array;
  END;

RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the objective&amp;nbsp;is to lump all numeric variables together&amp;nbsp;(with the exception of ID) and find their running sum, something like this could work:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* untested code */
DATA want;
  SET have;
  BY id;
  
  /* id is numeric and it will be summed; thus negate it ... */
  obs_total = SUM(of _numeric_) - id;
  
  IF first.id THEN running_total = obs_total;
  ELSE             running_total + obs_total;

RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Oct 2015 17:48:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-all-numeric-variables/m-p/228478#M267924</guid>
      <dc:creator>hbi</dc:creator>
      <dc:date>2015-10-05T17:48:03Z</dc:date>
    </item>
  </channel>
</rss>

