<?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 Listing variables with same prefix in proc sql join in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Listing-variables-with-same-prefix-in-proc-sql-join/m-p/580914#M13618</link>
    <description>&lt;P&gt;I'm trying to clean up my code and wondering if there is a simpler way to list the REFERER_SOURCE variables instead of listing them all out since they have the same prefix? I know you can reference variables like REFERER_SOURCE_1-REFERER_SOURCE_7 in other commands, but struggling to figure this out with the left join. THanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table adms_4 as&lt;BR /&gt;select a.*, b.REFERER_SOURCE_1, b.REFERER_SOURCE_2, b.REFERER_SOURCE_3, b.REFERER_SOURCE_4, b.REFERER_SOURCE_5, b.REFERER_SOURCE_6, b.REFERER_SOURCE_7&lt;BR /&gt;from adms_3 a left join RS2 b on a.ADMISSION_ID = b.ADMISSION_ID;&lt;BR /&gt;quit;&lt;/P&gt;</description>
    <pubDate>Tue, 13 Aug 2019 17:58:42 GMT</pubDate>
    <dc:creator>accintron</dc:creator>
    <dc:date>2019-08-13T17:58:42Z</dc:date>
    <item>
      <title>Listing variables with same prefix in proc sql join</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Listing-variables-with-same-prefix-in-proc-sql-join/m-p/580914#M13618</link>
      <description>&lt;P&gt;I'm trying to clean up my code and wondering if there is a simpler way to list the REFERER_SOURCE variables instead of listing them all out since they have the same prefix? I know you can reference variables like REFERER_SOURCE_1-REFERER_SOURCE_7 in other commands, but struggling to figure this out with the left join. THanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table adms_4 as&lt;BR /&gt;select a.*, b.REFERER_SOURCE_1, b.REFERER_SOURCE_2, b.REFERER_SOURCE_3, b.REFERER_SOURCE_4, b.REFERER_SOURCE_5, b.REFERER_SOURCE_6, b.REFERER_SOURCE_7&lt;BR /&gt;from adms_3 a left join RS2 b on a.ADMISSION_ID = b.ADMISSION_ID;&lt;BR /&gt;quit;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Aug 2019 17:58:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Listing-variables-with-same-prefix-in-proc-sql-join/m-p/580914#M13618</guid>
      <dc:creator>accintron</dc:creator>
      <dc:date>2019-08-13T17:58:42Z</dc:date>
    </item>
    <item>
      <title>Re: Listing variables with same prefix in proc sql join</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Listing-variables-with-same-prefix-in-proc-sql-join/m-p/580919#M13619</link>
      <description>&lt;P&gt;SAS/SQL syntax doesn't provide variable list shortcuts. But dataset options do. In some circumstances you can request all variables&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;... select b.*, ...&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and exclude unwanted columns using dataset option &lt;STRONG&gt;drop&lt;/STRONG&gt; on input&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;... from myData(drop=junk1) as b ...&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;or on output&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;create table want(drop=junk10) as ...&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;or include only wanted columns with dataset option &lt;STRONG&gt;keep &lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;... left join RS2(keep=ADMISSION_ID REFERER_SOURCE_:&amp;nbsp; )&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Aug 2019 18:19:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Listing-variables-with-same-prefix-in-proc-sql-join/m-p/580919#M13619</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2019-08-13T18:19:18Z</dc:date>
    </item>
    <item>
      <title>Re: Listing variables with same prefix in proc sql join</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Listing-variables-with-same-prefix-in-proc-sql-join/m-p/580920#M13620</link>
      <description>&lt;P&gt;Or do a DATA step merge, where you can abbreviate the list of variables desired to&amp;nbsp;&lt;STRONG&gt;REFERER_SOURCE_:&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Aug 2019 18:22:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Listing-variables-with-same-prefix-in-proc-sql-join/m-p/580920#M13620</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-08-13T18:22:04Z</dc:date>
    </item>
    <item>
      <title>Re: Listing variables with same prefix in proc sql join</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Listing-variables-with-same-prefix-in-proc-sql-join/m-p/580924#M13621</link>
      <description>&lt;P&gt;Are you doing a many-to-many merge?&lt;/P&gt;
&lt;P&gt;If not then just use normal SAS code instead of SQL and then you can use variable lists in many places.&lt;/P&gt;
&lt;P&gt;For this example you can probably just use a KEEP= option on the RS2 input dataset in either SQL or normal code.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data adms_4;
  merge   adms_3(in=in_a) RS2 (keep=admission_id referer_source_: );
  by ADMISSION_ID;
  if in_a;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In SQL you might want to also rename the duplicate ADMISSION_ID column so that you can use * in your column list without getting warnings/notes about duplicate names. You can then DROP it from the output dataset.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;create table adms_4(drop=id_B) as
  select * 
  from adms_3 a 
  left join RS2(keep=admission_id referer_source_: rename=(admission_id=id_B)) b 
  on a.ADMISSION_ID = b.id_B
;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Aug 2019 18:55:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Listing-variables-with-same-prefix-in-proc-sql-join/m-p/580924#M13621</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-08-13T18:55:55Z</dc:date>
    </item>
    <item>
      <title>Re: Listing variables with same prefix in proc sql join</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Listing-variables-with-same-prefix-in-proc-sql-join/m-p/581119#M13636</link>
      <description>&lt;P&gt;Ah, thank you! Not doing many to many merge. These suggestions are so helpful and straightforward . I appreciate it!&lt;/P&gt;</description>
      <pubDate>Wed, 14 Aug 2019 14:20:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Listing-variables-with-same-prefix-in-proc-sql-join/m-p/581119#M13636</guid>
      <dc:creator>accintron</dc:creator>
      <dc:date>2019-08-14T14:20:40Z</dc:date>
    </item>
  </channel>
</rss>

