<?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 proc sql sum several variables and group by in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-sum-several-variables-and-group-by/m-p/282439#M57403</link>
    <description>&lt;P&gt;Dear experts,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;let's assume the following variables: shop_ID, bolean_variable, revenue201601, &lt;SPAN&gt;revenue201602, revenue201603, revenue201603&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;for a total of 10 observations.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;how can set a proc sql as it follows: proc sql; create table abc as select &amp;nbsp;&lt;/SPAN&gt;&amp;nbsp;&lt;SPAN&gt;shop_ID, bolean_variable, sum (&lt;STRONG&gt;revenue:&lt;/STRONG&gt;) from xyz group by&amp;nbsp;&amp;nbsp;&lt;SPAN&gt;shop_ID, bolean_variable ;quit;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;How can I specify to do it for some variables without listing them one by one?&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;Thanki in advance and BRs, SH&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 06 Jul 2016 14:41:22 GMT</pubDate>
    <dc:creator>Sir_Highbury</dc:creator>
    <dc:date>2016-07-06T14:41:22Z</dc:date>
    <item>
      <title>proc sql sum several variables and group by</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-sum-several-variables-and-group-by/m-p/282439#M57403</link>
      <description>&lt;P&gt;Dear experts,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;let's assume the following variables: shop_ID, bolean_variable, revenue201601, &lt;SPAN&gt;revenue201602, revenue201603, revenue201603&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;for a total of 10 observations.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;how can set a proc sql as it follows: proc sql; create table abc as select &amp;nbsp;&lt;/SPAN&gt;&amp;nbsp;&lt;SPAN&gt;shop_ID, bolean_variable, sum (&lt;STRONG&gt;revenue:&lt;/STRONG&gt;) from xyz group by&amp;nbsp;&amp;nbsp;&lt;SPAN&gt;shop_ID, bolean_variable ;quit;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;How can I specify to do it for some variables without listing them one by one?&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;Thanki in advance and BRs, SH&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Jul 2016 14:41:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-sum-several-variables-and-group-by/m-p/282439#M57403</guid>
      <dc:creator>Sir_Highbury</dc:creator>
      <dc:date>2016-07-06T14:41:22Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql sum several variables and group by</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-sum-several-variables-and-group-by/m-p/282444#M57405</link>
      <description>&lt;P&gt;You cannot specify variable ranges or wildcards in the SELECT clause as you would have in a datastep. But you can use KEEP on the table:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
   select *
   from have(keep=shop_id revenue2016:);
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You could also use shortcut notation like VAR1-VAR8, VAR1--VAR8, _NUMERIC_ etc. But always on the KEEP, never on the SELECT.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards, Jan.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Jul 2016 14:59:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-sum-several-variables-and-group-by/m-p/282444#M57405</guid>
      <dc:creator>jklaverstijn</dc:creator>
      <dc:date>2016-07-06T14:59:41Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql sum several variables and group by</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-sum-several-variables-and-group-by/m-p/282445#M57406</link>
      <description>&lt;P&gt;Are you looking to sum within year the 4 revenue variables and then get a single aggregate total or do you want 4 aggregate sums?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think if your main criteria is the use of variable lists you may want to look to something like Proc summary or means instead of sql.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc summary data= xyz nway;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; class shop_id bolean_variable;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; var revenue: ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; output out=abc (drop= _:) sum=;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Jul 2016 15:03:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-sum-several-variables-and-group-by/m-p/282445#M57406</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-07-06T15:03:53Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql sum several variables and group by</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-sum-several-variables-and-group-by/m-p/282449#M57408</link>
      <description>&lt;P&gt;As was noted, there are simpler solutions than using SQL.&amp;nbsp; But if you are determined to use a SQL solution, macro language can help.&amp;nbsp; Your intention makes a difference.&amp;nbsp; Which of these would be correct within a SELECT statement?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;sum(revenue1) as revenue1, sum(revenue2) as revenue2, sum(revenue3) as revenue3&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;vs.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;sum(revenue1, revenue2, revenue3) as tot_revenue&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If PROC SUMMARY works for what you need, that would be simpler.&amp;nbsp; No need to mess with macro language unless necessary.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Jul 2016 15:14:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-sum-several-variables-and-group-by/m-p/282449#M57408</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-07-06T15:14:52Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql sum several variables and group by</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-sum-several-variables-and-group-by/m-p/282499#M57419</link>
      <description>&lt;P&gt;This is DEFINITELY a task for PROC SUMMARY as&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw﻿&lt;/a&gt;&amp;nbsp;notes.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Jul 2016 18:09:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-sum-several-variables-and-group-by/m-p/282499#M57419</guid>
      <dc:creator>sh0e</dc:creator>
      <dc:date>2016-07-06T18:09:37Z</dc:date>
    </item>
  </channel>
</rss>

