<?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: merging multiple variables with same name in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/merging-multiple-variables-with-same-name/m-p/333202#M9820</link>
    <description>Thank you</description>
    <pubDate>Wed, 15 Feb 2017 22:27:27 GMT</pubDate>
    <dc:creator>r4321</dc:creator>
    <dc:date>2017-02-15T22:27:27Z</dc:date>
    <item>
      <title>merging multiple variables with same name</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/merging-multiple-variables-with-same-name/m-p/332835#M9793</link>
      <description>&lt;P&gt;Hello all, I'm trying to merge multiple variables with the same name. Instead of writing it out, I would like to find a shortcut if possible. Here is my current code:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table all.as6 as select a.*, b.var5_101, b.var5_102, b.var5_103, b.var5_104, b.var5_105, b.var5_106, b.var5_107, b.var5_108, b.var5_109, b.var5_110, b.var5_111, b.var5_112, b.var5_113, b.var5_114, b.var5_115, b.var5_116, b.var5_117, b.var5_118, b.var5_119, b.var5_120, b.var5_121, b.var5_122, b.var5_123, b.var5_124, b.var5_125, b.var5_126, b.var5_127, b.var5_128, b.var5_129, b.var5_130&lt;BR /&gt;from all.as5 as a left join all.asa1 as b&lt;BR /&gt;on a.key = b.key;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to just do something like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;SPAN&gt;proc sql;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;create table all.as6 as select a.*, &lt;/SPAN&gt;&lt;SPAN&gt;b.var5_101-var5_130&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;from all.as5 as a left join all.asa1 as b&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;on a.key = b.key; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;quit;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Unfortunately, this code does not work. What can I do?&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;R&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Feb 2017 23:19:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/merging-multiple-variables-with-same-name/m-p/332835#M9793</guid>
      <dc:creator>r4321</dc:creator>
      <dc:date>2017-02-14T23:19:27Z</dc:date>
    </item>
    <item>
      <title>Re: merging multiple variables with same name</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/merging-multiple-variables-with-same-name/m-p/332836#M9794</link>
      <description>&lt;P&gt;Use a data step and you can rename enmasse. I don't see any renames in your code so not sure how you're currently doing it.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Ie&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;rename =( var1-var10 = new_var1-new_var10)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SQL doesn't allow variable shortcuts or variable lists.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Feb 2017 23:28:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/merging-multiple-variables-with-same-name/m-p/332836#M9794</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-02-14T23:28:03Z</dc:date>
    </item>
    <item>
      <title>Re: merging multiple variables with same name</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/merging-multiple-variables-with-same-name/m-p/332844#M9795</link>
      <description>Thanks - I know about the renaming, but is there a way I can merge the same way? There's gotta be a quicker way than typing out each variable name one by one.</description>
      <pubDate>Wed, 15 Feb 2017 00:24:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/merging-multiple-variables-with-same-name/m-p/332844#M9795</guid>
      <dc:creator>r4321</dc:creator>
      <dc:date>2017-02-15T00:24:29Z</dc:date>
    </item>
    <item>
      <title>Re: merging multiple variables with same name</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/merging-multiple-variables-with-same-name/m-p/332859#M9796</link>
      <description>&lt;P&gt;Not in SQL. There are no variable lists or shortcuts in SQL.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Though you're not using any renaming, it's only mentioned in the title so where does the same name issue come into play?&lt;/P&gt;
&lt;P&gt;Why not just use a * as well?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use FEEDBACK to select and then grab the code from the log and modify.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql FEEDBACK;&lt;/P&gt;
&lt;P&gt;create table want as&lt;/P&gt;
&lt;P&gt;select *&amp;nbsp;&lt;/P&gt;
&lt;P&gt;from sashelp.class;&lt;/P&gt;
&lt;P&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or you can do the join in a data step, but you'll still need to deal with the variables with the same names.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Feb 2017 01:58:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/merging-multiple-variables-with-same-name/m-p/332859#M9796</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-02-15T01:58:05Z</dc:date>
    </item>
    <item>
      <title>Re: merging multiple variables with same name</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/merging-multiple-variables-with-same-name/m-p/332862#M9797</link>
      <description>&lt;PRE&gt;
Make a macro variable to hold these variable names.

data x;
 do i=101 to 130;
  output;
 end;
run;
proc sql;
select cats('b.var5_',i) into : vars  separated by ','
 from x ;

create table all as 
 select a.*, &amp;amp;vars
  ................
quit;


&lt;/PRE&gt;</description>
      <pubDate>Wed, 15 Feb 2017 02:07:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/merging-multiple-variables-with-same-name/m-p/332862#M9797</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-02-15T02:07:03Z</dc:date>
    </item>
    <item>
      <title>Re: merging multiple variables with same name</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/merging-multiple-variables-with-same-name/m-p/332873#M9798</link>
      <description>&lt;P&gt;Another option:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Tom&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;%macro&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; &lt;STRONG&gt;&lt;I&gt;DoSQL&lt;/I&gt;&lt;/STRONG&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;create table work.as6 as select &lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;a.&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;*, &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;%Do&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; i = &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;101&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;%to&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;129&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;b.var5_&amp;amp;&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;i.&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;,&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;%end&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;b.var5_130&lt;/P&gt;
&lt;P&gt;from work.as5 as a left join work.asa1 as b&lt;/P&gt;
&lt;P&gt;on a.key = b.key;&lt;/P&gt;
&lt;P&gt;quit;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;%mend&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;%&lt;STRONG&gt;&lt;I&gt;DoSQL&lt;/I&gt;&lt;/STRONG&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Feb 2017 02:40:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/merging-multiple-variables-with-same-name/m-p/332873#M9798</guid>
      <dc:creator>TomKari</dc:creator>
      <dc:date>2017-02-15T02:40:44Z</dc:date>
    </item>
    <item>
      <title>Re: merging multiple variables with same name</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/merging-multiple-variables-with-same-name/m-p/333010#M9804</link>
      <description>&lt;P&gt;R,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;another quick option would be to use the power of data step and a view.&lt;/P&gt;
&lt;P&gt;-------------------------------------------------------------&lt;/P&gt;
&lt;P&gt;data work._t_asa1/view=work._t_asa1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;set all.asa1(keep=key var5_101-var130);&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;create table all.as6 as&lt;/P&gt;
&lt;P&gt;&amp;nbsp; select a.*,b.*&lt;/P&gt;
&lt;P&gt;&amp;nbsp; from all.as5 as a left join work._t_asa1 as b&lt;/P&gt;
&lt;P&gt;&amp;nbsp; on a.key=b.key;&lt;/P&gt;
&lt;P&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc datasets lib=work noprint; /* clean up */&lt;/P&gt;
&lt;P&gt;&amp;nbsp;delete _t_asa1/memtype=view;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;--------------------------------------------------------&lt;/P&gt;
&lt;P&gt;You'll get a dup key warning on the field "key" but it can be ignored.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Outside of that Tom's macro loop is a good option.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Steve&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Feb 2017 14:05:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/merging-multiple-variables-with-same-name/m-p/333010#M9804</guid>
      <dc:creator>SteveED</dc:creator>
      <dc:date>2017-02-15T14:05:04Z</dc:date>
    </item>
    <item>
      <title>Re: merging multiple variables with same name</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/merging-multiple-variables-with-same-name/m-p/333202#M9820</link>
      <description>Thank you</description>
      <pubDate>Wed, 15 Feb 2017 22:27:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/merging-multiple-variables-with-same-name/m-p/333202#M9820</guid>
      <dc:creator>r4321</dc:creator>
      <dc:date>2017-02-15T22:27:27Z</dc:date>
    </item>
    <item>
      <title>Re: merging multiple variables with same name</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/merging-multiple-variables-with-same-name/m-p/333203#M9821</link>
      <description>Thank you</description>
      <pubDate>Wed, 15 Feb 2017 22:27:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/merging-multiple-variables-with-same-name/m-p/333203#M9821</guid>
      <dc:creator>r4321</dc:creator>
      <dc:date>2017-02-15T22:27:41Z</dc:date>
    </item>
  </channel>
</rss>

