<?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: Need help calculating(summing) several variables as columns and not rows in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Need-help-calculating-summing-several-variables-as-columns-and/m-p/514819#M138853</link>
    <description>&lt;P&gt;Use a procedure which is designed to do summing = proc means, summary.&amp;nbsp; Am afraid Excel is not an acceptable format for providing data, but I assume that the variables are all numeric (otherwise how will you sum them).&amp;nbsp; Therefore using the proc means (or summary you can cheat a bit):&lt;/P&gt;
&lt;PRE&gt;proc means data=have;
  var _numeric_;
  output out=want sum= /autoname;
run;&lt;/PRE&gt;
&lt;P&gt;Will create want with all numeric variables summed up, named &amp;lt;variable&amp;gt;_sum.&lt;/P&gt;
&lt;P&gt;Post test data in the form of a datastep in a code window (its the {i} above post area) in future please.&lt;/P&gt;</description>
    <pubDate>Tue, 20 Nov 2018 16:26:20 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2018-11-20T16:26:20Z</dc:date>
    <item>
      <title>Need help calculating(summing) several variables as columns and not rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-calculating-summing-several-variables-as-columns-and/m-p/514817#M138851</link>
      <description>&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;BR /&gt;I need help to calculate the aggregated (sum) total of each column in my dataset.&amp;nbsp; This data set has over 100 variables.&amp;nbsp; The data set is attached as an excel file.&lt;/P&gt;&lt;P&gt;&amp;nbsp;I have tried to use proc sql and a&amp;nbsp; macro do loop but I keep getting errors when processing.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;BR /&gt;PROC IMPORT OUT= _1&amp;nbsp; DATAFILE= "C:\table.xls" ;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro waaa(start, end);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;BR /&gt;PROC SQL noprint;&lt;/P&gt;&lt;P&gt;%do j=&amp;amp;start %to &amp;amp;end ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;create table _N1 as&lt;/P&gt;&lt;P&gt;SELECT SUM(f&amp;amp;j) as _t&amp;amp;j&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;BR /&gt;FROM _1; %end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;BR /&gt;QUIT;&lt;BR /&gt;　&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;%waaa(start=1901, end=2016);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can anyone help?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 20 Nov 2018 16:21:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-calculating-summing-several-variables-as-columns-and/m-p/514817#M138851</guid>
      <dc:creator>yo1</dc:creator>
      <dc:date>2018-11-20T16:21:02Z</dc:date>
    </item>
    <item>
      <title>Re: Need help calculating(summing) several variables as columns and not rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-calculating-summing-several-variables-as-columns-and/m-p/514819#M138853</link>
      <description>&lt;P&gt;Use a procedure which is designed to do summing = proc means, summary.&amp;nbsp; Am afraid Excel is not an acceptable format for providing data, but I assume that the variables are all numeric (otherwise how will you sum them).&amp;nbsp; Therefore using the proc means (or summary you can cheat a bit):&lt;/P&gt;
&lt;PRE&gt;proc means data=have;
  var _numeric_;
  output out=want sum= /autoname;
run;&lt;/PRE&gt;
&lt;P&gt;Will create want with all numeric variables summed up, named &amp;lt;variable&amp;gt;_sum.&lt;/P&gt;
&lt;P&gt;Post test data in the form of a datastep in a code window (its the {i} above post area) in future please.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Nov 2018 16:26:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-calculating-summing-several-variables-as-columns-and/m-p/514819#M138853</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-11-20T16:26:20Z</dc:date>
    </item>
    <item>
      <title>Re: Need help calculating(summing) several variables as columns and not rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-calculating-summing-several-variables-as-columns-and/m-p/514820#M138854</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Proc summary data=have;
var f1901-f2016;
output out=want(drop=_type_ _freq_) sum=;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Is this what you are looking for ?&lt;/P&gt;</description>
      <pubDate>Tue, 20 Nov 2018 16:29:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-calculating-summing-several-variables-as-columns-and/m-p/514820#M138854</guid>
      <dc:creator>r_behata</dc:creator>
      <dc:date>2018-11-20T16:29:51Z</dc:date>
    </item>
    <item>
      <title>Re: Need help calculating(summing) several variables as columns and not rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-calculating-summing-several-variables-as-columns-and/m-p/514822#M138856</link>
      <description>&lt;P&gt;Yes, this is not appropriate use of macros here, use a PROC instead.&amp;nbsp;&amp;nbsp;Your code doesn't work because the SQL is embedded in the loop but has the same data set name. This means that each SQL call will overwrite the previous data. If you did want to do this in a macro, you'd have to move the loop to inside the SQL to generate the code for each variable. However, there are much easier ways.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See examples here:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://github.com/statgeek/SAS-Tutorials/blob/master/proc_means_basic.sas" target="_blank"&gt;https://github.com/statgeek/SAS-Tutorials/blob/master/proc_means_basic.sas&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And a video tutorial here:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://video.sas.com/detail/video/3306906230001/summary-statistics-using-sas-studio?autoStart=true&amp;amp;q=summary%20statistics" target="_blank"&gt;https://video.sas.com/detail/video/3306906230001/summary-statistics-using-sas-studio?autoStart=true&amp;amp;q=summary%20statistics&lt;/A&gt;&lt;/P&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;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/111307"&gt;@yo1&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello everyone,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;BR /&gt;I need help to calculate the aggregated (sum) total of each column in my dataset.&amp;nbsp; This data set has over 100 variables.&amp;nbsp; The data set is attached as an excel file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;I have tried to use proc sql and a&amp;nbsp; macro do loop but I keep getting errors when processing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;BR /&gt;PROC IMPORT OUT= _1&amp;nbsp; DATAFILE= "C:\table.xls" ;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;RUN;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro waaa(start, end);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;BR /&gt;PROC SQL noprint;&lt;/P&gt;
&lt;P&gt;%do j=&amp;amp;start %to &amp;amp;end ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;create table _N1 as&lt;/P&gt;
&lt;P&gt;SELECT SUM(f&amp;amp;j) as _t&amp;amp;j&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;BR /&gt;FROM _1; %end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;BR /&gt;QUIT;&lt;BR /&gt;　&lt;/P&gt;
&lt;P&gt;%mend;&lt;/P&gt;
&lt;P&gt;%waaa(start=1901, end=2016);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can anyone help?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Nov 2018 16:31:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-calculating-summing-several-variables-as-columns-and/m-p/514822#M138856</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-11-20T16:31:03Z</dc:date>
    </item>
    <item>
      <title>Re: Need help calculating(summing) several variables as columns and not rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-calculating-summing-several-variables-as-columns-and/m-p/514826#M138859</link>
      <description>&lt;P&gt;r_behata&amp;nbsp; that worked!!&amp;nbsp;&amp;nbsp;&amp;nbsp; Thank you so much.&amp;nbsp; I was googling for 2 hours and couldn't find an answer.&amp;nbsp;&amp;nbsp; Your solution is so simple its genius!&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;May the stars shine on you today!&lt;/P&gt;</description>
      <pubDate>Tue, 20 Nov 2018 16:36:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-calculating-summing-several-variables-as-columns-and/m-p/514826#M138859</guid>
      <dc:creator>yo1</dc:creator>
      <dc:date>2018-11-20T16:36:12Z</dc:date>
    </item>
  </channel>
</rss>

