<?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 Changing variable names using another dataset’s data in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Changing-variable-names-using-another-dataset-s-data/m-p/692003#M210716</link>
    <description>Hello,&lt;BR /&gt;&lt;BR /&gt;I need to change a large number of variable names of a dataset. The targeted names are included in another dataset as data. For example, there are two datasets, A and B. The variable names of A are a1 a2 a3. And B has two variables, of which names are b1 and b2. b2 has data: c1, c2, and c3. Then I want to replace a1-3 by c1-3. Could you please help? Thanks in advance.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Fri, 16 Oct 2020 01:01:17 GMT</pubDate>
    <dc:creator>IOT</dc:creator>
    <dc:date>2020-10-16T01:01:17Z</dc:date>
    <item>
      <title>Changing variable names using another dataset’s data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Changing-variable-names-using-another-dataset-s-data/m-p/692003#M210716</link>
      <description>Hello,&lt;BR /&gt;&lt;BR /&gt;I need to change a large number of variable names of a dataset. The targeted names are included in another dataset as data. For example, there are two datasets, A and B. The variable names of A are a1 a2 a3. And B has two variables, of which names are b1 and b2. b2 has data: c1, c2, and c3. Then I want to replace a1-3 by c1-3. Could you please help? Thanks in advance.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 16 Oct 2020 01:01:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Changing-variable-names-using-another-dataset-s-data/m-p/692003#M210716</guid>
      <dc:creator>IOT</dc:creator>
      <dc:date>2020-10-16T01:01:17Z</dc:date>
    </item>
    <item>
      <title>Re: Changing variable names using another dataset’s data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Changing-variable-names-using-another-dataset-s-data/m-p/692026#M210719</link>
      <description>&lt;P&gt;Like this?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data NAMES;
 input LIBNAME $ MEMNAME $ OLDNAME $ NEWNAME $;
cards;
WORK A a1 c1
WORK A a2 c2
WORK A a3 c3
run;

data _null_;
  set NAMES;
  call execute('proc datasets lib='||LIBNAME||' noprint;');
  call execute('  modify '||MEMNAME||';');
  call execute('  rename '||OLDNAME||'='||NEWNAME||';');
  call execute('run;');
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Oct 2020 01:23:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Changing-variable-names-using-another-dataset-s-data/m-p/692026#M210719</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-10-16T01:23:16Z</dc:date>
    </item>
    <item>
      <title>Re: Changing variable names using another dataset’s data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Changing-variable-names-using-another-dataset-s-data/m-p/692029#M210722</link>
      <description>&lt;P&gt;It can be done in a few different ways.&amp;nbsp; I think this one would be the easiest to understand. It uses CALL Execute to write code the uses the PROC DATASETS procedure to do the rename.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.have;
  x = 1; y = 'Y'; output;
run;

data renames;
  oldname = "X"; NewName = "X_NEW"; OUTPUT;
  oldname = "Y"; NewName = "Y_NEW"; OUTPUT;
run;

data _null_;
  set renames end= finished;
  if _n_ = 1 then do;
    call execute("proc datasets library=work nolist;");
    call execute(" modify have;");
  end;
  call execute(" rename " || oldname || " = " || NewName || ";");
  if finished then do;
    call execute("quit;");
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 16 Oct 2020 01:32:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Changing-variable-names-using-another-dataset-s-data/m-p/692029#M210722</guid>
      <dc:creator>CurtisMackWSIPP</dc:creator>
      <dc:date>2020-10-16T01:32:00Z</dc:date>
    </item>
    <item>
      <title>Re: Changing variable names using another dataset’s data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Changing-variable-names-using-another-dataset-s-data/m-p/692036#M210725</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt;'s code works. And to get the dataset NAMES used in his code, you can do this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=A (obs=0) out=A_t (keep=_NAME_ rename=(_NAME_=oldname));
    var :;
run;

data NAMES;
    set A_t;
    set B (keep=b2 rename=(b2=newname));
    libname='WORK';
    memname='A';
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 16 Oct 2020 02:56:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Changing-variable-names-using-another-dataset-s-data/m-p/692036#M210725</guid>
      <dc:creator>vellad</dc:creator>
      <dc:date>2020-10-16T02:56:33Z</dc:date>
    </item>
    <item>
      <title>Re: Changing variable names using another dataset’s data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Changing-variable-names-using-another-dataset-s-data/m-p/692067#M210742</link>
      <description>Thanks for the simple solution. It’s quite helpful. I appreciate the other answers as well.</description>
      <pubDate>Fri, 16 Oct 2020 08:02:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Changing-variable-names-using-another-dataset-s-data/m-p/692067#M210742</guid>
      <dc:creator>IOT</dc:creator>
      <dc:date>2020-10-16T08:02:19Z</dc:date>
    </item>
    <item>
      <title>Re: Changing variable names using another dataset’s data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Changing-variable-names-using-another-dataset-s-data/m-p/692200#M210815</link>
      <description>&lt;PRE&gt;Try using this code


data test;
input a1 a2 a3;
datalines;
1 2 3
4 5 6
7 8 9
;
run;


data var_names;
input var1 $2. var2 $3.;
datalines;
b1 c1
b2 c2
b3 c3
;
run;

data contents;
ds=open("test",'i');
num=attrn(ds,'nvars');
do v=1 to num;
vn=varname(ds,v);
output;
end;
run;

proc sql;
select  count(distinct var1)  into : count from var_names;
%let count=&amp;amp;count;
select distinct var2 into : newvar_1-: newvar_&amp;amp;count from var_names;
quit;

proc sql;
select count(distinct v) into : count1 from contents;
%let count1=&amp;amp;count1;
select distinct vn into : oldvar_1-:oldvar_&amp;amp;count1 from contents;
quit;

%put &amp;amp;oldvar_1 &amp;amp;oldvar_2 &amp;amp;oldvar_3;
%put &amp;amp;newvar_1 &amp;amp;newvar_2 &amp;amp;newvar_3;



data want1;
set test;
run;
%macro rename;

%do i=1 %to &amp;amp;count1.;


data want1;
set want1;
rename &amp;amp;&amp;amp;oldvar_&amp;amp;i..=&amp;amp;&amp;amp;newvar_&amp;amp;i..;
run;

%end;

%mend;
%rename; &lt;/PRE&gt;</description>
      <pubDate>Fri, 16 Oct 2020 18:11:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Changing-variable-names-using-another-dataset-s-data/m-p/692200#M210815</guid>
      <dc:creator>Venky3110</dc:creator>
      <dc:date>2020-10-16T18:11:59Z</dc:date>
    </item>
  </channel>
</rss>

