<?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: Change values of the first variable based on values of the second variable in Statistical Procedures</title>
    <link>https://communities.sas.com/t5/Statistical-Procedures/Change-values-of-the-first-variable-based-on-values-of-the/m-p/460827#M24064</link>
    <description>&lt;P&gt;Not "renaming" that means something else in SAS regardless of how you use your variable var1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One of the basic approaches to changing the value of a variable based on the value of a different variable is the IF /Then statement in a data step:&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; set have;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; If var1='A' and var2=1 then var1='A1';&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Some potential gotchas exist with this though. The variable var1 will have a length associated with the variable. If the length is 1 (one) then attempting to add more characters at the end will fail as there is no room for the additional variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can group similar values into a "DO block to avoid repeating some tests such as var1='A': The following code demonstrates that plus how to change the length of var1 if needed.&lt;/P&gt;
&lt;PRE&gt;data want;
   length var1 $ 5;
   set have;
   If var1='A' then do;
      if var2=1 then var1='A1';
      if var2=8 then var1='A2';
      if var2=25 then var1='A3';
   end;
run;&lt;/PRE&gt;</description>
    <pubDate>Tue, 08 May 2018 20:01:09 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2018-05-08T20:01:09Z</dc:date>
    <item>
      <title>Change values of the first variable based on values of the second variable</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Change-values-of-the-first-variable-based-on-values-of-the/m-p/460824#M24063</link>
      <description>&lt;P&gt;Hi Everyone!&lt;/P&gt;&lt;P&gt;How can i rename "A" in var1 into A1, A2 and A3 based on 1, 8, and 25 in var2?&lt;/P&gt;&lt;P&gt;i.e lets have:&lt;/P&gt;&lt;P&gt;var1&amp;nbsp; var2&lt;/P&gt;&lt;P&gt;A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;8&lt;/P&gt;&lt;P&gt;A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;25&lt;/P&gt;&lt;P&gt;B&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3&lt;/P&gt;&lt;P&gt;c&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 5&lt;/P&gt;&lt;P&gt;A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 8&lt;/P&gt;&lt;P&gt;A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;25&lt;/P&gt;&lt;P&gt;into&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;var1&amp;nbsp; var2&lt;/P&gt;&lt;P&gt;A1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;A 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;8&lt;/P&gt;&lt;P&gt;A 3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;25&lt;/P&gt;&lt;P&gt;B&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3&lt;/P&gt;&lt;P&gt;c&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;5&lt;/P&gt;&lt;P&gt;A1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;A 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 8&lt;/P&gt;&lt;P&gt;A 3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;25&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you alot!&lt;/P&gt;</description>
      <pubDate>Tue, 08 May 2018 19:51:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Change-values-of-the-first-variable-based-on-values-of-the/m-p/460824#M24063</guid>
      <dc:creator>Lijuu</dc:creator>
      <dc:date>2018-05-08T19:51:25Z</dc:date>
    </item>
    <item>
      <title>Re: Change values of the first variable based on values of the second variable</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Change-values-of-the-first-variable-based-on-values-of-the/m-p/460827#M24064</link>
      <description>&lt;P&gt;Not "renaming" that means something else in SAS regardless of how you use your variable var1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One of the basic approaches to changing the value of a variable based on the value of a different variable is the IF /Then statement in a data step:&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; set have;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; If var1='A' and var2=1 then var1='A1';&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Some potential gotchas exist with this though. The variable var1 will have a length associated with the variable. If the length is 1 (one) then attempting to add more characters at the end will fail as there is no room for the additional variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can group similar values into a "DO block to avoid repeating some tests such as var1='A': The following code demonstrates that plus how to change the length of var1 if needed.&lt;/P&gt;
&lt;PRE&gt;data want;
   length var1 $ 5;
   set have;
   If var1='A' then do;
      if var2=1 then var1='A1';
      if var2=8 then var1='A2';
      if var2=25 then var1='A3';
   end;
run;&lt;/PRE&gt;</description>
      <pubDate>Tue, 08 May 2018 20:01:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Change-values-of-the-first-variable-based-on-values-of-the/m-p/460827#M24064</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-05-08T20:01:09Z</dc:date>
    </item>
    <item>
      <title>Re: Change values of the first variable based on values of the second variable</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Change-values-of-the-first-variable-based-on-values-of-the/m-p/460868#M24068</link>
      <description>Thank you much in advance!!</description>
      <pubDate>Tue, 08 May 2018 21:36:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Change-values-of-the-first-variable-based-on-values-of-the/m-p/460868#M24068</guid>
      <dc:creator>Lijuu</dc:creator>
      <dc:date>2018-05-08T21:36:09Z</dc:date>
    </item>
  </channel>
</rss>

