<?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: Replace a variable name conditionally in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Replace-a-variable-name-conditionally/m-p/556274#M154962</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;, Thank you for your help. You have catched my point perfectly. Here is what I want.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data NBI_data;
input Structure_Number_08 Substrucuture_condition  Year_built
datalines;
11700121    021 8 1910
11700121    021 8 1910 
11700121    021 7 1910
11700121    021 7 1910
11700121    021 6 1910
2630 8 2012
2630 8 2012
2630 8 2012
2630 7 2012
2630 7 2012
.
.
.
;
run;

data_Nbi_Correlation;
input Old_structure_Number_008 Strucutre_number_008;
datalines
11700121    021 16349
.
.
.
;
run;

*/The data I want shall have all values renamed with new values and also keep those already with new values.*/;
Data want;
input Structure_Number_08 Substrucuture_condition  Year_built
datalines;
16349 8 1910
16349 8 1910 
16349 7 1910
16349 7 1910
16349 6 1910
2630 8 2012
2630 8 2012
2630 8 2012
2630 7 2012
2630 7 2012
   &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I would be happy if you demonstrate the code based on my example. The value (&lt;CODE class=" language-sas"&gt;11700121 021&lt;/CODE&gt;) is one value.&lt;/P&gt;</description>
    <pubDate>Sun, 05 May 2019 16:00:13 GMT</pubDate>
    <dc:creator>mmhxc5</dc:creator>
    <dc:date>2019-05-05T16:00:13Z</dc:date>
    <item>
      <title>Replace a variable name conditionally</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-a-variable-name-conditionally/m-p/555989#M154810</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have&amp;nbsp; a SAS dataset of over 600,000 data points. A variable called Structure_Number_008 is the structure identifier. Some strucures has got Old_name and New_name both due to some rules and both names are available for some structures in the SAS data set.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have another excel file which has the Old_name and New_name correlation for all structures in two columns.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the SAS data set, I want to replace all Old_name with its New_name while keeping the structures which has only New_name.&lt;/P&gt;&lt;P&gt;I would be grateful if anyone could help me to do the job.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;</description>
      <pubDate>Fri, 03 May 2019 15:54:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-a-variable-name-conditionally/m-p/555989#M154810</guid>
      <dc:creator>mmhxc5</dc:creator>
      <dc:date>2019-05-03T15:54:51Z</dc:date>
    </item>
    <item>
      <title>Re: Replace a variable name conditionally</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-a-variable-name-conditionally/m-p/555995#M154811</link>
      <description>&lt;P&gt;Are you wanting to change data or the name of the variable that holds the data?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please supply some example data before and after the change, using &lt;FONT face="courier new,courier"&gt;datalines&lt;/FONT&gt; in SAS so that others can use it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Amir.&lt;/P&gt;</description>
      <pubDate>Fri, 03 May 2019 16:02:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-a-variable-name-conditionally/m-p/555995#M154811</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2019-05-03T16:02:33Z</dc:date>
    </item>
    <item>
      <title>Re: Replace a variable name conditionally</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-a-variable-name-conditionally/m-p/556002#M154815</link>
      <description>&lt;P&gt;Fully agree to &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/22588"&gt;@Amir&lt;/a&gt;: title and description don't match, so please clarify what you have and what you need, preferable with example dataset (NOT excel-files).&lt;/P&gt;</description>
      <pubDate>Fri, 03 May 2019 16:31:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-a-variable-name-conditionally/m-p/556002#M154815</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2019-05-03T16:31:08Z</dc:date>
    </item>
    <item>
      <title>Re: Replace a variable name conditionally</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-a-variable-name-conditionally/m-p/556055#M154835</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/22588"&gt;@Amir&lt;/a&gt;and &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15475"&gt;@andreas_lds&lt;/a&gt;, thank you for asking more clarification. I want to replace only the Old_name and keep all the data relating to the name while changing it to the New_name.&lt;/P&gt;&lt;P&gt;The SAS data set has Structure_Number_008 which is a mixture of Old_name and New_name such as the &lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SAS dataset with OLD_name.JPG" style="width: 426px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/29193iEE27D63DCFB34D8E/image-size/large?v=v2&amp;amp;px=999" role="button" title="SAS dataset with OLD_name.JPG" alt="SAS dataset with OLD_name.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;The Old_name is available in the excel file which correlates it to the New_name as below.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Old_name and New_name Correlation.JPG" style="width: 415px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/29194i682E0BF1F558AC9F/image-size/large?v=v2&amp;amp;px=999" role="button" title="Old_name and New_name Correlation.JPG" alt="Old_name and New_name Correlation.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I want to replace all Old_names in the SAS file if&amp;nbsp; the Old_name and its New_name is available in the excel file. I just want to replace the name and keep all the data related to the Old_name with the New_name.&lt;/P&gt;</description>
      <pubDate>Fri, 03 May 2019 19:10:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-a-variable-name-conditionally/m-p/556055#M154835</guid>
      <dc:creator>mmhxc5</dc:creator>
      <dc:date>2019-05-03T19:10:02Z</dc:date>
    </item>
    <item>
      <title>Re: Replace a variable name conditionally</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-a-variable-name-conditionally/m-p/556064#M154843</link>
      <description>Please be careful with your example. You may be posting information that you should not post. Just a thought. If you need to delete it please do so.</description>
      <pubDate>Fri, 03 May 2019 19:22:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-a-variable-name-conditionally/m-p/556064#M154843</guid>
      <dc:creator>jffeudo86</dc:creator>
      <dc:date>2019-05-03T19:22:10Z</dc:date>
    </item>
    <item>
      <title>Re: Replace a variable name conditionally</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-a-variable-name-conditionally/m-p/556148#M154889</link>
      <description>To rename a variable use either the rename statement in a data-step or proc datasets.</description>
      <pubDate>Sat, 04 May 2019 05:35:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-a-variable-name-conditionally/m-p/556148#M154889</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2019-05-04T05:35:27Z</dc:date>
    </item>
    <item>
      <title>Re: Replace a variable name conditionally</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-a-variable-name-conditionally/m-p/556206#M154931</link>
      <description>&lt;P&gt;It sounds like you want to change the value of a variable based on some lookup table?&lt;/P&gt;
&lt;P&gt;So if&amp;nbsp;&lt;SPAN&gt;Structure_Number_008 is equal to 'XXXX' and there is record in the lookup table that says XXXX is really YYYY want to change from XXXX to YYYY?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;If so then a format is an easy way to do that.&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format ;
value $rename
 'XXXX' = 'YYYY'
;
quit;

data want;
  set have ;
  Structure_Number_008 = put(Stucture_Number_008,$rename.);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;There are ways to convert a lookup table into the dataset structure that you can use to create a format.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;So if you had a dataset that looked like:&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data renames;
  infile cards dsd dlm='|' truncover ;
  input oldname :$200. newname :$200.;
cards;
XXXX|YYYY
A b C|ABC
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;You could make a format from that by first creating a dataset in the right form and then passing the dataset to PROC FORMAT.&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data format;
  retain fmtname '$rename' ;
  set renames;
  start=oldname;
  label=newname;
  keep fmtname start label;
run;
proc format cntlin=format;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 04 May 2019 17:47:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-a-variable-name-conditionally/m-p/556206#M154931</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-05-04T17:47:30Z</dc:date>
    </item>
    <item>
      <title>Re: Replace a variable name conditionally</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-a-variable-name-conditionally/m-p/556274#M154962</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;, Thank you for your help. You have catched my point perfectly. Here is what I want.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data NBI_data;
input Structure_Number_08 Substrucuture_condition  Year_built
datalines;
11700121    021 8 1910
11700121    021 8 1910 
11700121    021 7 1910
11700121    021 7 1910
11700121    021 6 1910
2630 8 2012
2630 8 2012
2630 8 2012
2630 7 2012
2630 7 2012
.
.
.
;
run;

data_Nbi_Correlation;
input Old_structure_Number_008 Strucutre_number_008;
datalines
11700121    021 16349
.
.
.
;
run;

*/The data I want shall have all values renamed with new values and also keep those already with new values.*/;
Data want;
input Structure_Number_08 Substrucuture_condition  Year_built
datalines;
16349 8 1910
16349 8 1910 
16349 7 1910
16349 7 1910
16349 6 1910
2630 8 2012
2630 8 2012
2630 8 2012
2630 7 2012
2630 7 2012
   &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I would be happy if you demonstrate the code based on my example. The value (&lt;CODE class=" language-sas"&gt;11700121 021&lt;/CODE&gt;) is one value.&lt;/P&gt;</description>
      <pubDate>Sun, 05 May 2019 16:00:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-a-variable-name-conditionally/m-p/556274#M154962</guid>
      <dc:creator>mmhxc5</dc:creator>
      <dc:date>2019-05-05T16:00:13Z</dc:date>
    </item>
    <item>
      <title>Re: Replace a variable name conditionally</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-a-variable-name-conditionally/m-p/556276#M154963</link>
      <description>&lt;P&gt;You can work it out yourself.&amp;nbsp; You table NBI_CORRELATION is like the RENAMES table in my example.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could use it to make a format like I did.&lt;/P&gt;
&lt;P&gt;Or just use it in some other way.&lt;/P&gt;</description>
      <pubDate>Sun, 05 May 2019 16:08:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-a-variable-name-conditionally/m-p/556276#M154963</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-05-05T16:08:24Z</dc:date>
    </item>
  </channel>
</rss>

