<?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: How to combine rows of data using PROC SQL's sum funciton for a large number of variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-combine-rows-of-data-using-PROC-SQL-s-sum-funciton-for-a/m-p/338308#M77012</link>
    <description>&lt;P&gt;There are no wildcards or shortcuts for variables in SQL. Use one of the summary procedures such as PROC MEANS, SUMMARY or&amp;nbsp;UNIVARIATE. You can use the variable lists or shortcuts in the VAR statement, or if you exclude a VAR statement all numeric variables will be summarized.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc means data=have nway noprint;&lt;BR /&gt; class year;&lt;BR /&gt; var pop mt;&lt;BR /&gt; output out=want sum= /autoname;&lt;BR /&gt;run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;EDIT: See the ways to specify a variable list here:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/lrcon/69852/HTML/default/viewer.htm#p0wphcpsfgx6o7n1sjtqzizp1n39.htm&amp;nbsp;" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrcon/69852/HTML/default/viewer.htm#p0wphcpsfgx6o7n1sjtqzizp1n39.htm&amp;nbsp;&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Sun, 05 Mar 2017 22:19:24 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2017-03-05T22:19:24Z</dc:date>
    <item>
      <title>How to combine rows of data using PROC SQL's sum funciton for a large number of variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-combine-rows-of-data-using-PROC-SQL-s-sum-funciton-for-a/m-p/338302#M77009</link>
      <description>&lt;P&gt;I am trying to sum two rows of data for each year in a longitudinal data set. &amp;nbsp;The following code using PROC SQL works but I will have a much larger data set with &amp;nbsp;many variables that need to be summed. &amp;nbsp;In the code blow I have to give a sum command in SQL for each variable. &amp;nbsp;Wildcards in SQL? &amp;nbsp;Thank you.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data have;&lt;BR /&gt; input id year pop mt;&lt;BR /&gt;datalines;&lt;BR /&gt;2 2010 95247.15 677297&lt;BR /&gt;2 2011 98970 527331&lt;BR /&gt;2 2012 100780 665843&lt;BR /&gt;2 2013 101575 613688&lt;BR /&gt;2 2014 102731 537205&lt;BR /&gt;4 2010 16884.8 6640444&lt;BR /&gt;4 2011 16250 6639846&lt;BR /&gt;4 2012 16180 6407018&lt;BR /&gt;4 2013 15937 6757319&lt;BR /&gt;4 2014 15961 5404051&lt;BR /&gt;;&lt;BR /&gt;Proc sql;&lt;BR /&gt;create table want as&lt;BR /&gt;select year, sum(pop) as sum_pop, sum(mt) as sum_mt&lt;BR /&gt;from have&lt;BR /&gt;group by year;&lt;BR /&gt;quit;&lt;/P&gt;</description>
      <pubDate>Sun, 05 Mar 2017 21:08:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-combine-rows-of-data-using-PROC-SQL-s-sum-funciton-for-a/m-p/338302#M77009</guid>
      <dc:creator>doylejm</dc:creator>
      <dc:date>2017-03-05T21:08:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to combine rows of data using PROC SQL's sum funciton for a large number of variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-combine-rows-of-data-using-PROC-SQL-s-sum-funciton-for-a/m-p/338308#M77012</link>
      <description>&lt;P&gt;There are no wildcards or shortcuts for variables in SQL. Use one of the summary procedures such as PROC MEANS, SUMMARY or&amp;nbsp;UNIVARIATE. You can use the variable lists or shortcuts in the VAR statement, or if you exclude a VAR statement all numeric variables will be summarized.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc means data=have nway noprint;&lt;BR /&gt; class year;&lt;BR /&gt; var pop mt;&lt;BR /&gt; output out=want sum= /autoname;&lt;BR /&gt;run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;EDIT: See the ways to specify a variable list here:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/lrcon/69852/HTML/default/viewer.htm#p0wphcpsfgx6o7n1sjtqzizp1n39.htm&amp;nbsp;" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrcon/69852/HTML/default/viewer.htm#p0wphcpsfgx6o7n1sjtqzizp1n39.htm&amp;nbsp;&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 05 Mar 2017 22:19:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-combine-rows-of-data-using-PROC-SQL-s-sum-funciton-for-a/m-p/338308#M77012</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-03-05T22:19:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to combine rows of data using PROC SQL's sum funciton for a large number of variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-combine-rows-of-data-using-PROC-SQL-s-sum-funciton-for-a/m-p/338314#M77017</link>
      <description>&lt;P&gt;Post a list that includes all of the variables that you'd like to select using wildcards.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 05 Mar 2017 22:14:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-combine-rows-of-data-using-PROC-SQL-s-sum-funciton-for-a/m-p/338314#M77017</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-03-05T22:14:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to combine rows of data using PROC SQL's sum funciton for a large number of variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-combine-rows-of-data-using-PROC-SQL-s-sum-funciton-for-a/m-p/338322#M77022</link>
      <description>&lt;P&gt;If you absolutely want to do this with SQL, you will have to resort to macro programming:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
proc sql noprint;
select catt("sum(", name, ") as", " sum_", name)
into :varlist separated by ", "
from dictionary.columns
where libname="WORK" and memname="HAVE" and upcase(name) not in ("ID","YEAR");
create table want as
select
    id, year, &amp;amp;varlist.
from have
group by id, year;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 05 Mar 2017 23:24:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-combine-rows-of-data-using-PROC-SQL-s-sum-funciton-for-a/m-p/338322#M77022</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2017-03-05T23:24:39Z</dc:date>
    </item>
  </channel>
</rss>

