<?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 variable names using macro or array in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Rename-variable-names-using-macro-or-array/m-p/435827#M282074</link>
    <description>Thanks! Your method also works!</description>
    <pubDate>Fri, 09 Feb 2018 19:50:05 GMT</pubDate>
    <dc:creator>Alucard_L</dc:creator>
    <dc:date>2018-02-09T19:50:05Z</dc:date>
    <item>
      <title>Rename variable names using macro or array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rename-variable-names-using-macro-or-array/m-p/435744#M282066</link>
      <description>&lt;P&gt;Hello everyone. I have two datasets A and B. &amp;nbsp;They have some same variables but with different names. I'd like to rename these variable names in A using the variable names in B. For example, I have variable names StaffID, Cartype, Food, Alcohol, ... up to 200 variables in dataset A. &amp;nbsp;ID, car, food, alcohollevel,.... &amp;nbsp;up to 300 variables in dataset B. I want to rename staffID=ID, cartype=car, alcohol= alcohollevel. Is there a way to rename all the 200 variables in dataset A using array or macros?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;</description>
      <pubDate>Fri, 09 Feb 2018 17:54:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rename-variable-names-using-macro-or-array/m-p/435744#M282066</guid>
      <dc:creator>Alucard_L</dc:creator>
      <dc:date>2018-02-09T17:54:50Z</dc:date>
    </item>
    <item>
      <title>Re: Rename variable names using macro or array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rename-variable-names-using-macro-or-array/m-p/435771#M282067</link>
      <description>&lt;P&gt;Are the data sets ordered in the exact same manner - variables are listed in the exact same order?&lt;/P&gt;
&lt;P&gt;How do you know which names you want from which data set?&lt;/P&gt;</description>
      <pubDate>Fri, 09 Feb 2018 18:21:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rename-variable-names-using-macro-or-array/m-p/435771#M282067</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-02-09T18:21:31Z</dc:date>
    </item>
    <item>
      <title>Re: Rename variable names using macro or array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rename-variable-names-using-macro-or-array/m-p/435776#M282068</link>
      <description>They are not in the same order. Variable names in dataset B are the names I want. I need to change variable names in dataset A. I have the mapping chart. So I know which variable maps to which.</description>
      <pubDate>Fri, 09 Feb 2018 18:26:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rename-variable-names-using-macro-or-array/m-p/435776#M282068</guid>
      <dc:creator>Alucard_L</dc:creator>
      <dc:date>2018-02-09T18:26:08Z</dc:date>
    </item>
    <item>
      <title>Re: Rename variable names using macro or array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rename-variable-names-using-macro-or-array/m-p/435779#M282069</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/192480"&gt;@Alucard_L&lt;/a&gt; wrote:&lt;BR /&gt;They are not in the same order. Variable names in dataset B are the names I want. I need to change variable names in dataset A. I have the mapping chart. So I know which variable maps to which.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Show your mapping chart.&lt;/P&gt;
&lt;P&gt;If you can create a data step with the old/new pairs then it is very likely we can use that with Proc Datasets to change as requested.&lt;/P&gt;</description>
      <pubDate>Fri, 09 Feb 2018 18:28:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rename-variable-names-using-macro-or-array/m-p/435779#M282069</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-02-09T18:28:48Z</dc:date>
    </item>
    <item>
      <title>Re: Rename variable names using macro or array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rename-variable-names-using-macro-or-array/m-p/435781#M282070</link>
      <description>&lt;P&gt;mapping chart&lt;BR /&gt;A &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; B&lt;BR /&gt;StaffID &amp;nbsp; &amp;nbsp; &amp;nbsp;ID&lt;BR /&gt;Cartype &amp;nbsp; &amp;nbsp;car&lt;BR /&gt;Food &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;food&lt;BR /&gt;Alcohol &amp;nbsp; &amp;nbsp; alcohollevel&lt;/P&gt;</description>
      <pubDate>Fri, 09 Feb 2018 18:33:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rename-variable-names-using-macro-or-array/m-p/435781#M282070</guid>
      <dc:creator>Alucard_L</dc:creator>
      <dc:date>2018-02-09T18:33:17Z</dc:date>
    </item>
    <item>
      <title>Re: Rename variable names using macro or array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rename-variable-names-using-macro-or-array/m-p/435786#M282071</link>
      <description>&lt;P&gt;&lt;A href="https://communities.sas.com/t5/Base-SAS-Programming/How-to-write-a-macro-for-renaming-lots-of-variables/td-p/128183" target="_blank"&gt;https://communities.sas.com/t5/Base-SAS-Programming/How-to-write-a-macro-for-renaming-lots-of-variables/td-p/128183&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Feb 2018 18:37:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rename-variable-names-using-macro-or-array/m-p/435786#M282071</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-02-09T18:37:24Z</dc:date>
    </item>
    <item>
      <title>Re: Rename variable names using macro or array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rename-variable-names-using-macro-or-array/m-p/435792#M282072</link>
      <description>&lt;P&gt;GIven that you haven't done this before, here is a simple way.&amp;nbsp; Create your own RENAME statement, stored in a file.&amp;nbsp; For example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;filename myfile 'path to a file of your choice';&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data _null_;&lt;/P&gt;
&lt;P&gt;file myfile noprint;&lt;/P&gt;
&lt;P&gt;put 'rename';&lt;/P&gt;
&lt;P&gt;do until (done);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; set mapping_chart end=done;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; put a '=' b;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;put ';' ;&lt;/P&gt;
&lt;P&gt;stop;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Inspect the file, so you understand how the program works.&amp;nbsp; Then apply it in whatever way you are comfortable.&amp;nbsp; A DATA step has the disadvantage of needing to read the data, but the advantage of being simple:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;%include myfile;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or you can use PROC DATASETS with the MODIFY statement.&amp;nbsp; Either way should get the job done.&lt;/P&gt;</description>
      <pubDate>Fri, 09 Feb 2018 18:48:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rename-variable-names-using-macro-or-array/m-p/435792#M282072</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-02-09T18:48:02Z</dc:date>
    </item>
    <item>
      <title>Re: Rename variable names using macro or array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rename-variable-names-using-macro-or-array/m-p/435793#M282073</link>
      <description>&lt;P&gt;The following should work:&lt;/P&gt;
&lt;PRE&gt;data a;
  input StaffID Cartype Food Alcohol;
  cards;
1 2 3 4
5 6 7 8
;

data B;
  input ID car food alcohollevel;
  cards;
1 2 3 4
5 6 7 8
;

data mapping_chart;
  informat A B $32.;
  input A B;
  cards;
StaffID      ID
Cartype    car
Food        food
Alcohol     alcohollevel
;

proc sql;
  select catt(A,'=',B)
    into :renames separated by ' '
      from mapping_chart
  ;
quit;

proc datasets lib=work nolist;
  modify A;
    rename &amp;amp;renames.;
quit;
run;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Feb 2018 18:48:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rename-variable-names-using-macro-or-array/m-p/435793#M282073</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2018-02-09T18:48:13Z</dc:date>
    </item>
    <item>
      <title>Re: Rename variable names using macro or array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rename-variable-names-using-macro-or-array/m-p/435827#M282074</link>
      <description>Thanks! Your method also works!</description>
      <pubDate>Fri, 09 Feb 2018 19:50:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rename-variable-names-using-macro-or-array/m-p/435827#M282074</guid>
      <dc:creator>Alucard_L</dc:creator>
      <dc:date>2018-02-09T19:50:05Z</dc:date>
    </item>
  </channel>
</rss>

