<?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 How to rename a variable in a dataset with value of another variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-rename-a-variable-in-a-dataset-with-value-of-another/m-p/418788#M102901</link>
    <description>&lt;P&gt;I want to rename a variable with value of another variable. This is what I have.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data c;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;array a{3} $ a1-a3 ("column1","column2","column3");&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;array b{3} $ b1-b3; drop a1-a3;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data d;&lt;/P&gt;&lt;P&gt;set c(rename=(b1=a1));&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the dataset d, I want to rename the variable b1 with the value of a1 which is "column1". How is it possible?&lt;/P&gt;</description>
    <pubDate>Wed, 06 Dec 2017 13:41:59 GMT</pubDate>
    <dc:creator>smohando</dc:creator>
    <dc:date>2017-12-06T13:41:59Z</dc:date>
    <item>
      <title>How to rename a variable in a dataset with value of another variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-rename-a-variable-in-a-dataset-with-value-of-another/m-p/418788#M102901</link>
      <description>&lt;P&gt;I want to rename a variable with value of another variable. This is what I have.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data c;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;array a{3} $ a1-a3 ("column1","column2","column3");&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;array b{3} $ b1-b3; drop a1-a3;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data d;&lt;/P&gt;&lt;P&gt;set c(rename=(b1=a1));&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the dataset d, I want to rename the variable b1 with the value of a1 which is "column1". How is it possible?&lt;/P&gt;</description>
      <pubDate>Wed, 06 Dec 2017 13:41:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-rename-a-variable-in-a-dataset-with-value-of-another/m-p/418788#M102901</guid>
      <dc:creator>smohando</dc:creator>
      <dc:date>2017-12-06T13:41:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to rename a variable in a dataset with value of another variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-rename-a-variable-in-a-dataset-with-value-of-another/m-p/418795#M102904</link>
      <description>&lt;P&gt;Search is your friend, use the search bar to find things:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/forums/searchpage/tab/message?advanced=false&amp;amp;allow_punctuation=false&amp;amp;q=rename+a+list+of+variables" target="_blank"&gt;https://communities.sas.com/t5/forums/searchpage/tab/message?advanced=false&amp;amp;allow_punctuation=false&amp;amp;q=rename+a+list+of+variables&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example, a simple way, if you know the variable names:&lt;/P&gt;
&lt;PRE&gt;data d;
  set c;
  rename b1--b3=column1--column3;
run;&lt;/PRE&gt;
&lt;P&gt;Or do you mean the "column" part can be different.&amp;nbsp; In which case a data _null_ step to generate a proc datasets may be appropriate.&amp;nbsp; POst some actual test data which reflect what you have.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Dec 2017 14:05:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-rename-a-variable-in-a-dataset-with-value-of-another/m-p/418795#M102904</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-12-06T14:05:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to rename a variable in a dataset with value of another variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-rename-a-variable-in-a-dataset-with-value-of-another/m-p/418800#M102908</link>
      <description>I want to rename with the value of the variable which is set dynamically. I cannot hardcode that in my code.</description>
      <pubDate>Wed, 06 Dec 2017 14:26:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-rename-a-variable-in-a-dataset-with-value-of-another/m-p/418800#M102908</guid>
      <dc:creator>smohando</dc:creator>
      <dc:date>2017-12-06T14:26:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to rename a variable in a dataset with value of another variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-rename-a-variable-in-a-dataset-with-value-of-another/m-p/418803#M102909</link>
      <description>&lt;P&gt;Then show us an example of the input, with the dynamic naming values, and an example of the output.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Dec 2017 14:36:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-rename-a-variable-in-a-dataset-with-value-of-another/m-p/418803#M102909</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-12-06T14:36:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to rename a variable in a dataset with value of another variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-rename-a-variable-in-a-dataset-with-value-of-another/m-p/418807#M102912</link>
      <description>&lt;P&gt;As&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt;&amp;nbsp;proposed: use&amp;nbsp;&lt;STRONG&gt;&lt;SPAN&gt;a data _null_ step to generate a proc datasets.&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;You can use either&amp;nbsp;&lt;STRONG&gt;call execute&lt;/STRONG&gt; to submit the proc datasets statements or&amp;nbsp;&lt;/P&gt;
&lt;P&gt;generate and create a temporary program (text file) to run using %include &amp;lt;fileref&amp;gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Anyway you should know which value will rename which variable, or what is the logic to match&lt;/P&gt;
&lt;P&gt;new name with the old name.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you have a psecific example - how do you get the new names and how to match it to&lt;/P&gt;
&lt;P&gt;variables of a given dataset (c in your post).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Dec 2017 14:51:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-rename-a-variable-in-a-dataset-with-value-of-another/m-p/418807#M102912</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-12-06T14:51:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to rename a variable in a dataset with value of another variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-rename-a-variable-in-a-dataset-with-value-of-another/m-p/418859#M102939</link>
      <description>&lt;P&gt;This is an example of labels being driven from a data set, but you can easily modify it for the RENAME statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://gist.github.com/statgeek/f18931085f6a0009185c" target="_blank"&gt;https://gist.github.com/statgeek/f18931085f6a0009185c&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*Create label data set;
data label_data_set;
length name label $25.;
name="Sex"; label="Gender"; output;
name="height"; label="Height (in)"; output;
name="weight"; label="Weight (lbs)"; output;
run;
 
 
*Create sample dataset to apply label;
data class;
set sashelp.class;
run;
 
 
*Create macro variable that holds label statement;
proc sql noprint;
select catx("=", name, quote(trim(label)))
  into :label_list separated by " "
from label_data_set;
quit;
 
 
*Display macro variable in log;
%put &amp;amp;label_list.;
 
 
*Apply labels without recreating dataset;
proc datasets library=work;
modify class;
label &amp;amp;label_list.;
run;quit;
 
 
*Print the dataset to display new labels;
proc print data=class label noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 06 Dec 2017 16:32:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-rename-a-variable-in-a-dataset-with-value-of-another/m-p/418859#M102939</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-12-06T16:32:03Z</dc:date>
    </item>
  </channel>
</rss>

