<?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: Rename all variables starting with the same preffix to a different preffix in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Rename-all-variables-starting-with-the-same-preffix-to-a/m-p/611281#M178138</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/293494"&gt;@Suzy_Cat&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi Paige,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for the suggestions. It is working when I tried below:&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token function"&gt;rename&lt;/SPAN&gt; Cat_:&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;Sohi_:&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Did you mean to say that it is NOT working??&lt;/P&gt;</description>
    <pubDate>Thu, 12 Dec 2019 13:03:09 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2019-12-12T13:03:09Z</dc:date>
    <item>
      <title>Rename all variables starting with the same preffix to a different preffix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rename-all-variables-starting-with-the-same-preffix-to-a/m-p/611152#M178073</link>
      <description>&lt;P&gt;Hi there&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can anyone help me on renaming all variables starting with the same preffix to a different prefix?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cheers&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sue&lt;/P&gt;</description>
      <pubDate>Wed, 11 Dec 2019 20:51:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rename-all-variables-starting-with-the-same-preffix-to-a/m-p/611152#M178073</guid>
      <dc:creator>Suzy_Cat</dc:creator>
      <dc:date>2019-12-11T20:51:49Z</dc:date>
    </item>
    <item>
      <title>Re: Rename all variables starting with the same preffix to a different preffix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rename-all-variables-starting-with-the-same-preffix-to-a/m-p/611159#M178076</link>
      <description>&lt;P&gt;Rename x1-x100 to be y1-y100.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In a SAS DATA step, use:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;rename x1-x100=y1-y100;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Dec 2019 21:10:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rename-all-variables-starting-with-the-same-preffix-to-a/m-p/611159#M178076</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-12-11T21:10:33Z</dc:date>
    </item>
    <item>
      <title>Re: Rename all variables starting with the same preffix to a different preffix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rename-all-variables-starting-with-the-same-preffix-to-a/m-p/611188#M178086</link>
      <description>&lt;P&gt;Hi Paige,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for the suggestions. It is working when I tried below:&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token function"&gt;rename&lt;/SPAN&gt; Cat_:&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;Sohi_:&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token punctuation"&gt;the name of those datasets is not ending with digits and&amp;nbsp;they are random combination&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Dec 2019 01:19:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rename-all-variables-starting-with-the-same-preffix-to-a/m-p/611188#M178086</guid>
      <dc:creator>Suzy_Cat</dc:creator>
      <dc:date>2019-12-12T01:19:52Z</dc:date>
    </item>
    <item>
      <title>Re: Rename all variables starting with the same preffix to a different preffix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rename-all-variables-starting-with-the-same-preffix-to-a/m-p/611281#M178138</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/293494"&gt;@Suzy_Cat&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi Paige,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for the suggestions. It is working when I tried below:&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token function"&gt;rename&lt;/SPAN&gt; Cat_:&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;Sohi_:&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Did you mean to say that it is NOT working??&lt;/P&gt;</description>
      <pubDate>Thu, 12 Dec 2019 13:03:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rename-all-variables-starting-with-the-same-preffix-to-a/m-p/611281#M178138</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-12-12T13:03:09Z</dc:date>
    </item>
    <item>
      <title>Re: Rename all variables starting with the same preffix to a different preffix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rename-all-variables-starting-with-the-same-preffix-to-a/m-p/611294#M178144</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have; 
    input a_a a_b a_1 a_2 a_1000;
    cards;
1 2 3 4 5
;
run;

data _NULL_;
    call execute('data want; set have; rename');

    do until(fend);
        set sashelp.vcolumn end=fend;
        where libname="WORK" and memname="HAVE" and NAME like 'a_%';
        call execute(cats(NAME,'=b_', substr(NAME,3)));
    end;

call execute('; run;');
stop;
run;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 12 Dec 2019 13:40:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rename-all-variables-starting-with-the-same-preffix-to-a/m-p/611294#M178144</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2019-12-12T13:40:18Z</dc:date>
    </item>
    <item>
      <title>Re: Rename all variables starting with the same preffix to a different preffix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rename-all-variables-starting-with-the-same-preffix-to-a/m-p/611785#M178391</link>
      <description>&lt;P&gt;Hi Paige&amp;nbsp;, yes you were right. did not realize there was a type while I actually meant it not working as expected.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Sat, 14 Dec 2019 10:10:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rename-all-variables-starting-with-the-same-preffix-to-a/m-p/611785#M178391</guid>
      <dc:creator>Suzy_Cat</dc:creator>
      <dc:date>2019-12-14T10:10:29Z</dc:date>
    </item>
    <item>
      <title>Re: Rename all variables starting with the same preffix to a different preffix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rename-all-variables-starting-with-the-same-preffix-to-a/m-p/611803#M178406</link>
      <description>&lt;P&gt;It is impossible for that syntax to work given how the : suffix works in variable lists.&amp;nbsp; When you use the : suffix you are asking SAS to list all variable in the current data step that start with that prefix.&amp;nbsp; So when you use it on the right of the equal sign in a RENAME statement it will fail in two ways.&amp;nbsp; Either it won't find the variables since they haven't been defined yet. Or it will find the variables, in which case they cannot be used as the new names since they already exist.&lt;/P&gt;</description>
      <pubDate>Sat, 14 Dec 2019 17:53:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rename-all-variables-starting-with-the-same-preffix-to-a/m-p/611803#M178406</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-12-14T17:53:26Z</dc:date>
    </item>
    <item>
      <title>Re: Rename all variables starting with the same preffix to a different preffix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rename-all-variables-starting-with-the-same-preffix-to-a/m-p/611919#M178463</link>
      <description>&lt;P&gt;Cheers Tom &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 15 Dec 2019 20:49:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rename-all-variables-starting-with-the-same-preffix-to-a/m-p/611919#M178463</guid>
      <dc:creator>Suzy_Cat</dc:creator>
      <dc:date>2019-12-15T20:49:18Z</dc:date>
    </item>
    <item>
      <title>Re: Rename all variables starting with the same preffix to a different preffix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rename-all-variables-starting-with-the-same-preffix-to-a/m-p/611942#M178468</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/293494"&gt;@Suzy_Cat&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi there&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can anyone help me on renaming all variables starting with the same preffix to a different prefix?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cheers&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sue&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/30622"&gt;@gamotte&lt;/a&gt;&amp;nbsp;'s solution works fine, but would perform poorly if the target dataset was large.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is another approach:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
   length foo a_a a_b x_y x_z a_c bar blah 8;
run;

proc sql noprint;
   select name into :vars separated by " "
   from dictionary.columns
   where libname="WORK" 
     and memname="HAVE"
     and name like "a_%"
   ;
quit;

%put &amp;amp;=vars;

%macro code;
&amp;amp;word=newprefix_%scan(&amp;amp;word,2,_)
%mend;

proc datasets lib=work nolist;
   modify have;
   rename %loop(&amp;amp;vars);
quit;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;A href="https://github.com/scottbass/SAS/blob/master/Macro/loop.sas" target="_blank"&gt;https://github.com/scottbass/SAS/blob/master/Macro/loop.sas&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Dec 2019 02:50:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rename-all-variables-starting-with-the-same-preffix-to-a/m-p/611942#M178468</guid>
      <dc:creator>ScottBass</dc:creator>
      <dc:date>2019-12-16T02:50:21Z</dc:date>
    </item>
    <item>
      <title>Re: Rename all variables starting with the same preffix to a different preffix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rename-all-variables-starting-with-the-same-preffix-to-a/m-p/611943#M178469</link>
      <description>&lt;P&gt;I'm glad you said that &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15043"&gt;@ScottBass&lt;/a&gt;. Rename using PROC DATASETS is preferable to rename in a DATA step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Even more compact code, with no macro looping&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
   select cats(name,'=',tranwrd(name,'a_','b_')) into :renames separated by " "
   from dictionary.columns
   where libname="WORK" 
     and memname="HAVE"
     and name eqt "a_"
   ;
quit;
proc datasets library=work nolist;
    modify have;
    rename &amp;amp;renames;
quit;
  
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 16 Dec 2019 14:39:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rename-all-variables-starting-with-the-same-preffix-to-a/m-p/611943#M178469</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-12-16T14:39:40Z</dc:date>
    </item>
    <item>
      <title>Re: Rename all variables starting with the same preffix to a different preffix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rename-all-variables-starting-with-the-same-preffix-to-a/m-p/611944#M178470</link>
      <description>You guys are awesome! provided more effective ways. good learning! Thanks a lot &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Mon, 16 Dec 2019 03:13:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rename-all-variables-starting-with-the-same-preffix-to-a/m-p/611944#M178470</guid>
      <dc:creator>Suzy_Cat</dc:creator>
      <dc:date>2019-12-16T03:13:10Z</dc:date>
    </item>
    <item>
      <title>Re: Rename all variables starting with the same preffix to a different preffix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rename-all-variables-starting-with-the-same-preffix-to-a/m-p/611951#M178473</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;Yep your code is more compact.&amp;nbsp; I find my %loop macro so useful (to me anyway) that I may have a bit of tunnel vision.&lt;/P&gt;</description>
      <pubDate>Mon, 16 Dec 2019 05:02:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rename-all-variables-starting-with-the-same-preffix-to-a/m-p/611951#M178473</guid>
      <dc:creator>ScottBass</dc:creator>
      <dc:date>2019-12-16T05:02:47Z</dc:date>
    </item>
    <item>
      <title>Re: Rename all variables starting with the same preffix to a different preffix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rename-all-variables-starting-with-the-same-preffix-to-a/m-p/611993#M178494</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15043"&gt;@ScottBass&lt;/a&gt; you don't even show your %loop macro, so your code above won't work for anyone but you.&lt;/P&gt;</description>
      <pubDate>Mon, 16 Dec 2019 11:48:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rename-all-variables-starting-with-the-same-preffix-to-a/m-p/611993#M178494</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-12-16T11:48:14Z</dc:date>
    </item>
  </channel>
</rss>

