<?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: renaming a variable inside a macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/renaming-a-variable-inside-a-macro/m-p/400188#M97018</link>
    <description>Automatically renaming variables will work only if you are 100% sure, that each variables name with the appended postfix is shorter than 32 chars.&lt;BR /&gt;&lt;BR /&gt;Depending on what you want to do with the result of the comparison, using proc compare can be the easier solution.</description>
    <pubDate>Mon, 02 Oct 2017 05:26:36 GMT</pubDate>
    <dc:creator>error_prone</dc:creator>
    <dc:date>2017-10-02T05:26:36Z</dc:date>
    <item>
      <title>renaming a variable inside a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/renaming-a-variable-inside-a-macro/m-p/400142#M97003</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have the following macro:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro varz(variable);
data qc2;
set qc;
keep gvkey fyear &amp;amp;variable;
rename &amp;amp;variable=&amp;amp;variable.._qc;
run;
%mend;

%varz(sales);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So here I want to create a data table qc2 which will include the variables gvkey, fyear and sales from the original table qc, and then rename sales to sales_qc, but it is this renaming part which causes errors (if it is omitted then the macro works).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Sun, 01 Oct 2017 17:35:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/renaming-a-variable-inside-a-macro/m-p/400142#M97003</guid>
      <dc:creator>ilikesas</dc:creator>
      <dc:date>2017-10-01T17:35:08Z</dc:date>
    </item>
    <item>
      <title>Re: renaming a variable inside a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/renaming-a-variable-inside-a-macro/m-p/400146#M97004</link>
      <description>&lt;P&gt;Don't use a datastep to rename a variable, use proc datasets instead, there is no need to do a full iteration, when you just want to change metadata. And: why do you want a macro?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To solve the error in your code, reduce the number of dots between &amp;amp;variable and _qc to one.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 01 Oct 2017 17:52:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/renaming-a-variable-inside-a-macro/m-p/400146#M97004</guid>
      <dc:creator>error_prone</dc:creator>
      <dc:date>2017-10-01T17:52:27Z</dc:date>
    </item>
    <item>
      <title>Re: renaming a variable inside a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/renaming-a-variable-inside-a-macro/m-p/400181#M97014</link>
      <description>&lt;P&gt;I have 2 datasets: qc and cc, and there are variables with identical names in both datasets. I just wanted a quick way to compare the variables from the datasets. Here is the full code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro varz(variable);
data qc2;
set qc;
keep gvkey fyear &amp;amp;variable;
rename &amp;amp;variable=&amp;amp;variable._qc;
run;

data cc2;
set cc;
keep gvkey fyear &amp;amp;variable;
rename &amp;amp;variable=&amp;amp;variable._cc;
run;

data want;
merge qc2 cc2;
by gvkey fyear;
run;

data want;
set want;
diff = &amp;amp;variable._qc - &amp;amp;variable._cc;
run;

proc means data=want;
run;

%mend;

%varz(sale);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 02 Oct 2017 00:06:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/renaming-a-variable-inside-a-macro/m-p/400181#M97014</guid>
      <dc:creator>ilikesas</dc:creator>
      <dc:date>2017-10-02T00:06:21Z</dc:date>
    </item>
    <item>
      <title>Re: renaming a variable inside a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/renaming-a-variable-inside-a-macro/m-p/400182#M97015</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12982"&gt;@ilikesas&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;The following might give you the idea how you could go about this.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.demo;
  set sashelp.class;
run;

proc sql noprint;
  select
    cats(name,'= demo_',name) 
      into :rename_list separated by ' '
  from dictionary.columns
  where libname='WORK' and memname='DEMO' and upcase(name) not in ('NAME','HEIGHT')
  ;
quit;

proc datasets lib=work nolist;
  modify demo;
    rename &amp;amp;rename_list;
  run;
quit;

proc contents data=demo;
run;quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Alternatively consider using Proc Compare.&lt;/P&gt;</description>
      <pubDate>Mon, 02 Oct 2017 01:22:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/renaming-a-variable-inside-a-macro/m-p/400182#M97015</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2017-10-02T01:22:40Z</dc:date>
    </item>
    <item>
      <title>Re: renaming a variable inside a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/renaming-a-variable-inside-a-macro/m-p/400188#M97018</link>
      <description>Automatically renaming variables will work only if you are 100% sure, that each variables name with the appended postfix is shorter than 32 chars.&lt;BR /&gt;&lt;BR /&gt;Depending on what you want to do with the result of the comparison, using proc compare can be the easier solution.</description>
      <pubDate>Mon, 02 Oct 2017 05:26:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/renaming-a-variable-inside-a-macro/m-p/400188#M97018</guid>
      <dc:creator>error_prone</dc:creator>
      <dc:date>2017-10-02T05:26:36Z</dc:date>
    </item>
  </channel>
</rss>

