<?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: Shortening my proc SQL with lots of variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Shortening-my-proc-SQL-with-lots-of-variables/m-p/444757#M111394</link>
    <description>&lt;P&gt;The easiest way to shorten the code is to get rid of SQL:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc summary data=have nway;&lt;/P&gt;
&lt;P&gt;class ID;&lt;/P&gt;
&lt;P&gt;var MQ1-MQ20 LQ1-LQ20;&lt;/P&gt;
&lt;P&gt;output out=want (drop=_type_ _freq_) max=;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
    <pubDate>Mon, 12 Mar 2018 14:06:15 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2018-03-12T14:06:15Z</dc:date>
    <item>
      <title>Shortening my proc SQL with lots of variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Shortening-my-proc-SQL-with-lots-of-variables/m-p/444750#M111392</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset containing an ID variable and the variables named MQ1 to MQ20 and LQ1 to LQ20. Each ID can have more than one value for MQ1 to MQ20 and LQ1 to LQ20.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now I want to create a new table keeping only the max value for each variable by ID using proc sql. My current code looks like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table&amp;nbsp;want as
select ID,&amp;nbsp;max(MQ1) as MQ1, max(MQ2) as MQ2, max(MQ3) as MQ3, max(MQ4) as MQ4, max(MQ5) as MQ5, max(MQ6) as MQ6, max(MQ7) as MQ7, max(MQ8) as MQ8, max(MQ9) as MQ9, max(MQ10) as MQ10, max(MQ11) as MQ11, max(MQ12) as MQ12, max(MQ13) as MQ13, max(MQ14) as MQ14, max(MQ15) as MQ15, max(MQ16) as MQ16, max(MQ17) as MQ17, max(MQ18) as MQ18, max(MQ19) as MQ19, max(MQ20) as MQ20, 
max(LQ1) as LQ1, max(LQ2) as LQ2, max(LQ3) as LQ3, max(LQ4) as LQ4, max(LQ5) as LQ5, max(LQ6) as LQ6, max(LQ7) as LQ7, max(LQ8) as LQ8, max(LQ9) as LQ9, max(LQ10) as LQ10, max(LQ11) as LQ11, max(LQ12) as LQ12, max(LQ13) as LQ13, max(LQ14) as LQ14, max(LQ15) as LQ15, max(LQ16) as LQ16, max(LQ17) as LQ17, max(LQ18) as LQ18, max(LQ19) as LQ19, max(LQ20) as LQ20
from&amp;nbsp;have
group by ID;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;As my code looks like this quite often I wonder whether there is an easy way to shorten this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Mar 2018 13:48:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Shortening-my-proc-SQL-with-lots-of-variables/m-p/444750#M111392</guid>
      <dc:creator>d_m</dc:creator>
      <dc:date>2018-03-12T13:48:47Z</dc:date>
    </item>
    <item>
      <title>Re: Shortening my proc SQL with lots of variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Shortening-my-proc-SQL-with-lots-of-variables/m-p/444757#M111394</link>
      <description>&lt;P&gt;The easiest way to shorten the code is to get rid of SQL:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc summary data=have nway;&lt;/P&gt;
&lt;P&gt;class ID;&lt;/P&gt;
&lt;P&gt;var MQ1-MQ20 LQ1-LQ20;&lt;/P&gt;
&lt;P&gt;output out=want (drop=_type_ _freq_) max=;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Mar 2018 14:06:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Shortening-my-proc-SQL-with-lots-of-variables/m-p/444757#M111394</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-03-12T14:06:15Z</dc:date>
    </item>
    <item>
      <title>Re: Shortening my proc SQL with lots of variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Shortening-my-proc-SQL-with-lots-of-variables/m-p/444759#M111395</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc means data=sashelp.class noprint nway;
class age;
var _numeric_;
output out=want max= / autoname;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 12 Mar 2018 14:08:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Shortening-my-proc-SQL-with-lots-of-variables/m-p/444759#M111395</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-03-12T14:08:11Z</dc:date>
    </item>
  </channel>
</rss>

