<?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: PROC SQL: default column names? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-default-column-names/m-p/764130#M242005</link>
    <description>&lt;P&gt;That DISTINCT is, as noted, redundant, and can be a real performance killer when working with large datasets.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;BIG&lt;/STRONG&gt; hint for the future: only use code that is needed (which implies that you have to know the function of each keyword used when working with code. Knowledge is Power.)&lt;/P&gt;
&lt;P&gt;If the PROC SUMMARY with CLASS cracks your memory limitations (may happen in multi-user environments, where memory must be limited to protect users from each other's code, and with a high cardinality of name), sort first and use BY:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have;
by name;
run;

proc summary data=have;
by name;
var amount hours rate;
output out=test (drop=_:) sum()=;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 26 Aug 2021 08:37:41 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2021-08-26T08:37:41Z</dc:date>
    <item>
      <title>PROC SQL: default column names?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-default-column-names/m-p/764077#M241974</link>
      <description>&lt;P&gt;When I aggregate a dataset via proc sql, I have to state the column name via "as" statement else the column will return as something like "TEMP005." There are so many cases where I just want the new aggregated column to have the same name as the var that I am aggregating. For example, say I have a table with four variables: name, amount, hours, and rate, and I am aggregating columns amount, hours, and rate.&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;proc sql;&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;create table test as&amp;nbsp;&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;select distinct name, sum(amount) as amount, sum(hours) as hours, sum(rate) as rate&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;from have&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;group by name&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;;&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;quit;&lt;/P&gt;&lt;P&gt;Is there any way to not have to write the "as" statement every single time and have the column names just default to whatever I am aggregating?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Aug 2021 00:01:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-default-column-names/m-p/764077#M241974</guid>
      <dc:creator>kchoi78</dc:creator>
      <dc:date>2021-08-26T00:01:48Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL: default column names?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-default-column-names/m-p/764078#M241975</link>
      <description>&lt;P&gt;I don't think there is any PROC SQL option for this but using macro could help:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro SQL_Sum (group = , var1 = , var2 = ,var3 = );

proc sql;
  create table test as 
  select &amp;amp;group, sum(&amp;amp;var1) as &amp;amp;var1, sum(&amp;amp;var2) as &amp;amp;var2, sum(&amp;amp;var3) as &amp;amp;var3
  from have
  group by &amp;amp;group
;
quit;

%mend SQL_Sum;

%SQL_Sum (group = name, var1 = amount, var2 = hours ,var3 = rate);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;BTW using DISTINCT is redundant when it is in a GROUP BY.&lt;/P&gt;</description>
      <pubDate>Thu, 26 Aug 2021 00:20:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-default-column-names/m-p/764078#M241975</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2021-08-26T00:20:08Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL: default column names?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-default-column-names/m-p/764079#M241976</link>
      <description>&lt;P&gt;Sometimes you may want to consider a different procedure.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Proc summary data=have nway;
   class name;
  var amount hours rate;
  output out= test (drop=_:) sum = ;
run;

&lt;/PRE&gt;
&lt;P&gt;Proc Means/ Summary also has an Autoname feature that will append the requested statistic(s) names to the variable such as:&lt;/P&gt;
&lt;PRE&gt;Proc summary data=have nway;
   class name;
  var amount hours rate;
  output out= test (drop=_:) sum = max= min= std= / autoname;
run;
&lt;/PRE&gt;
&lt;P&gt;Which will create amount_sum, amount_max, amount_min, amount_std (hope you get the picture).&lt;/P&gt;
&lt;P&gt;The NWAY on the Proc statement suppresses multiple levels of combinations of the class variables. Otherwise you get one row that has the statistic overall (and assorted combinations if more than one class variable is used). The drop= drops two variables that are automatically supplied: _freq_ how many observations used and _type_ which indicates which specific combination of class variables are represented for the observation in the output data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can also any of the forms of variable lists in Proc Means/Summary so you could get the summaries for all of the numeric variables by using:&amp;nbsp; var _numeric_; instead of listing all the variable names.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you just want to see the results and don't need a data set Proc Report or Tabulate will make summaries as well.&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;</description>
      <pubDate>Thu, 26 Aug 2021 00:32:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-default-column-names/m-p/764079#M241976</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-08-26T00:32:35Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL: default column names?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-default-column-names/m-p/764130#M242005</link>
      <description>&lt;P&gt;That DISTINCT is, as noted, redundant, and can be a real performance killer when working with large datasets.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;BIG&lt;/STRONG&gt; hint for the future: only use code that is needed (which implies that you have to know the function of each keyword used when working with code. Knowledge is Power.)&lt;/P&gt;
&lt;P&gt;If the PROC SUMMARY with CLASS cracks your memory limitations (may happen in multi-user environments, where memory must be limited to protect users from each other's code, and with a high cardinality of name), sort first and use BY:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have;
by name;
run;

proc summary data=have;
by name;
var amount hours rate;
output out=test (drop=_:) sum()=;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 26 Aug 2021 08:37:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-default-column-names/m-p/764130#M242005</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-08-26T08:37:41Z</dc:date>
    </item>
  </channel>
</rss>

