<?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 - select group variable with same prefix in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Proc-sql-select-group-variable-with-same-prefix/m-p/390787#M66150</link>
    <description>&lt;P&gt;You don't need the AS NEW_VAR_NAME part when it's not changing&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;inp.var1, inp.code_1&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;There is no way to short cut lists in SQL. You can use the FEEDBACK option to avoid typing it all out if you'd like.&lt;/P&gt;
&lt;P&gt;Run the proc with the FEEDBACK option and * for the INP table that you're interested in. Check the log for the query and copy that to your code window now. Edit as needed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql feedback;
create ...&lt;BR /&gt;select inp.*&lt;BR /&gt;from ....

quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 24 Aug 2017 22:42:43 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2017-08-24T22:42:43Z</dc:date>
    <item>
      <title>Proc sql - select group variable with same prefix</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-sql-select-group-variable-with-same-prefix/m-p/390784#M66149</link>
      <description>&lt;P&gt;I'd like to select group variable with same prefix Code_1-Code_30 in proc sql preferrentially selecting from "inp" data. It is tedious to spell out all 30 codes down there.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there any way to take advantage of the same prefix? in this context? &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
 create table ip_only(keep= var1 Code_:) as 
 SELECT inp.var1 as var1,
		inp.Code_1 as Code_1, 
		inp.Code_2 as Code_2 through Code_30
 FROM uniq_ip inp left join uniq_op outp
 on inp.personal_id = outp.personal_id;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I'm using SAS 9.4.&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 24 Aug 2017 22:32:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-sql-select-group-variable-with-same-prefix/m-p/390784#M66149</guid>
      <dc:creator>Cruise</dc:creator>
      <dc:date>2017-08-24T22:32:08Z</dc:date>
    </item>
    <item>
      <title>Re: Proc sql - select group variable with same prefix</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-sql-select-group-variable-with-same-prefix/m-p/390787#M66150</link>
      <description>&lt;P&gt;You don't need the AS NEW_VAR_NAME part when it's not changing&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;inp.var1, inp.code_1&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;There is no way to short cut lists in SQL. You can use the FEEDBACK option to avoid typing it all out if you'd like.&lt;/P&gt;
&lt;P&gt;Run the proc with the FEEDBACK option and * for the INP table that you're interested in. Check the log for the query and copy that to your code window now. Edit as needed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql feedback;
create ...&lt;BR /&gt;select inp.*&lt;BR /&gt;from ....

quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 24 Aug 2017 22:42:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-sql-select-group-variable-with-same-prefix/m-p/390787#M66150</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-08-24T22:42:43Z</dc:date>
    </item>
    <item>
      <title>Re: Proc sql - select group variable with same prefix</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-sql-select-group-variable-with-same-prefix/m-p/390790#M66151</link>
      <description>&lt;P&gt;No, SQL syntax does not support SAS variable lists.&lt;/P&gt;
&lt;P&gt;But you might be able to use &amp;nbsp;KEEP= and/or DELETE= dataset options so that you can just use * in the SELECT statement.&lt;/P&gt;
&lt;P&gt;So say you wanted to keep VAR1 and CODE1 to CODE30, but you also needed to keep PERSONAL_ID for use in the join condition. Your program might end up looking like this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table ip_only (drop=personal_id) as
  select inp.*
  from uniq_ip(keep=personal_id var1 code1-code30) inp
  left join uniq_op outp
    on inp.personal_id = outp.personal_id
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Aug 2017 13:26:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-sql-select-group-variable-with-same-prefix/m-p/390790#M66151</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-08-25T13:26:14Z</dc:date>
    </item>
    <item>
      <title>Re: Proc sql - select group variable with same prefix</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-sql-select-group-variable-with-same-prefix/m-p/390900#M66183</link>
      <description>&lt;PRE&gt;
As @Tom said before, SQL don't support variable listing method, depress.
But you can make a macro for it.


%macro xxxx;
PROC SQL;
 create table ip_only(keep= var1 Code_:) as 
 SELECT inp.var1 as var1,
    %do i=1 %to 30;
		inp.Code_&amp;amp;i as Code_&amp;amp;i
       %if &amp;amp;i ne 30 %then %do;  ,   %end; 
    %end;
 FROM uniq_ip inp left join uniq_op outp
 on inp.personal_id = outp.personal_id;
QUIT;
%mend;


%xxxx


&lt;/PRE&gt;</description>
      <pubDate>Fri, 25 Aug 2017 13:24:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-sql-select-group-variable-with-same-prefix/m-p/390900#M66183</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-08-25T13:24:58Z</dc:date>
    </item>
    <item>
      <title>Re: Proc sql - select group variable with same prefix</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-sql-select-group-variable-with-same-prefix/m-p/390919#M66185</link>
      <description>I have to work with my mentality. Every time when someone says macro I get freaked out &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Fri, 25 Aug 2017 14:34:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-sql-select-group-variable-with-same-prefix/m-p/390919#M66185</guid>
      <dc:creator>Cruise</dc:creator>
      <dc:date>2017-08-25T14:34:52Z</dc:date>
    </item>
    <item>
      <title>Re: Proc sql - select group variable with same prefix</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-sql-select-group-variable-with-same-prefix/m-p/390920#M66186</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&lt;/P&gt;&lt;P&gt;It worked out excellent. However at the price of taking out&amp;nbsp;all following conversions out of&amp;nbsp;sql to do in separate data steps. This is because I had several date variables needed conversion.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select 
 input(inp.birth_date,yymmdd8.) as birth_date,
      case when 
           (inp.Care_Date &amp;gt; outp.Care_Date) then 1
		   when 
		   (inp.Care_Date &amp;lt; outp.Care_Date) then 0
		   else 99
      end as first_op
from...&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Aug 2017 14:38:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-sql-select-group-variable-with-same-prefix/m-p/390920#M66186</guid>
      <dc:creator>Cruise</dc:creator>
      <dc:date>2017-08-25T14:38:49Z</dc:date>
    </item>
  </channel>
</rss>

