<?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: rename variable level in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/rename-a-variable-level/m-p/984191#M379677</link>
    <description>data new;&lt;BR /&gt;set long;&lt;BR /&gt;&lt;BR /&gt;if TRT='Jar' and  label in ('day0', 'day3') then TRT='Air';&lt;BR /&gt;&lt;BR /&gt;run;</description>
    <pubDate>Fri, 27 Feb 2026 07:05:03 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2026-02-27T07:05:03Z</dc:date>
    <item>
      <title>rename a variable level</title>
      <link>https://communities.sas.com/t5/SAS-Programming/rename-a-variable-level/m-p/984184#M379666</link>
      <description>&lt;P&gt;Dear SAS Community,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to rename the variable level 'Jar' to 'Air' for the variable TRT but only at day0 and day3 (not for day7) of the variable label. The problem I am having is that SAS is renaming for day0 and day3 but ignoring day7. I want to keep the levels 'Air' and 'Jar' for day7. I know I cannot use two WHERE statements but I included the second one so you understand what I want.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would greatly appreciate it your help!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data new;&lt;BR /&gt;set long;&lt;BR /&gt;where label in('day0', 'day3');&lt;BR /&gt;if TRT='Jar' then TRT='Air';&lt;BR /&gt;where label='day7';&lt;BR /&gt;if TRT='Air' then TRT='Air';&lt;BR /&gt;if TRT='Jar' then TRT='Jar';&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Feb 2026 23:14:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/rename-a-variable-level/m-p/984184#M379666</guid>
      <dc:creator>palolix</dc:creator>
      <dc:date>2026-02-26T23:14:30Z</dc:date>
    </item>
    <item>
      <title>rename variable level</title>
      <link>https://communities.sas.com/t5/SAS-Programming/rename-a-variable-level/m-p/984183#M379676</link>
      <description>&lt;P&gt;Dear SAS Community,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to rename the variable level 'Jar' to 'Air' for the variable TRT but only at day0 and day3 (not for day7) of the variable label. The problem I am having is that SAS is renaming for day0 and day3 but ignoring day7. I want to keep the levels 'Air' and 'Jar' for day7. I know I cannot use two WHERE statements but I included the second one so you understand what I want.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would greatly appreciate it your help!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data new;&lt;BR /&gt;set long;&lt;BR /&gt;where label in('day0', 'day3');&lt;BR /&gt;if TRT='Jar' then TRT='Air';&lt;BR /&gt;where label='day7';&lt;BR /&gt;if TRT='Air' then TRT='Air';&lt;BR /&gt;if TRT='Jar' then TRT='Jar';&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Feb 2026 23:11:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/rename-a-variable-level/m-p/984183#M379676</guid>
      <dc:creator>palolix</dc:creator>
      <dc:date>2026-02-26T23:11:41Z</dc:date>
    </item>
    <item>
      <title>Re: rename a variable level</title>
      <link>https://communities.sas.com/t5/SAS-Programming/rename-a-variable-level/m-p/984186#M379667</link>
      <description>&lt;P&gt;You cannot have two WHERE statements in a data step.&amp;nbsp; And the placement of the WHERE statement within the DATA step makes no difference.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I suspect what you want to do is include the extra conditions into your IF clauses.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But I am not sure because I do not understand the terminology you are using.&amp;nbsp; You say you want to&amp;nbsp; "rename a variable level", what does that mean?&amp;nbsp; &amp;nbsp;There is no variable named LEVEL referenced in your code.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Perhaps you mean you want to CHANGE a VALUE of a variable?&lt;/P&gt;
&lt;P&gt;If so then perhaps you mean you want to do this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data new;
  set long;
  if label in ('day0' 'day3') and TRT='Jar' then TRT='Air';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So for observations where LABEL is something else the value of TRT never changes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 27 Feb 2026 03:20:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/rename-a-variable-level/m-p/984186#M379667</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2026-02-27T03:20:16Z</dc:date>
    </item>
    <item>
      <title>Re: rename a variable level</title>
      <link>https://communities.sas.com/t5/SAS-Programming/rename-a-variable-level/m-p/984187#M379668</link>
      <description>&lt;P&gt;ELSE.&lt;/P&gt;
&lt;P&gt;You may want an if then/else construct. Otherwise ALL of those ifs get executed.&lt;/P&gt;
&lt;P&gt;Also you very likely do not want a WHERE as that removes observations for values on the where statement are not true. So the "day7" would never exist in the data set&lt;/P&gt;
&lt;P&gt;If this doesn't do what you want then&amp;nbsp; you should provide and example of the input data set and the desired result.&lt;/P&gt;
&lt;P&gt;Note: the&amp;nbsp; "else if" may not be needed at all because there is no reason to change the values, but I have shown it as it seems to parallel your thinking.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data new;
   set long;
   IF  label in('day0', 'day3') and TRT='Jar' then TRT='Air';
   Else if  label='day7' then do;
      if TRT='Air' then TRT='Air';
      if TRT='Jar' then TRT='Jar';
  end;
run;&lt;/PRE&gt;
&lt;P&gt;other code that would do the same thing:&lt;/P&gt;
&lt;PRE&gt;data new;
   set long;
   IF  label in('day0', 'day3') and TRT='Jar' then TRT='Air';
run;&lt;/PRE&gt;
&lt;P&gt;WHERE statement evaluates the values as they are brought into the data set. If the statement is not true then those obsesrvations, label='day7' (or any other value than day0 and day3) would not appear in the result at all. That where the limitation on single WHERE statement comes from.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Most condition operations based on values of variables would usually be better done with IF statements.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 27 Feb 2026 03:32:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/rename-a-variable-level/m-p/984187#M379668</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2026-02-27T03:32:19Z</dc:date>
    </item>
    <item>
      <title>Re: rename variable level</title>
      <link>https://communities.sas.com/t5/SAS-Programming/rename-a-variable-level/m-p/984191#M379677</link>
      <description>data new;&lt;BR /&gt;set long;&lt;BR /&gt;&lt;BR /&gt;if TRT='Jar' and  label in ('day0', 'day3') then TRT='Air';&lt;BR /&gt;&lt;BR /&gt;run;</description>
      <pubDate>Fri, 27 Feb 2026 07:05:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/rename-a-variable-level/m-p/984191#M379677</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2026-02-27T07:05:03Z</dc:date>
    </item>
    <item>
      <title>Re: rename variable level</title>
      <link>https://communities.sas.com/t5/SAS-Programming/rename-a-variable-level/m-p/984225#M379678</link>
      <description>Please do not double-post.</description>
      <pubDate>Fri, 27 Feb 2026 16:19:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/rename-a-variable-level/m-p/984225#M379678</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2026-02-27T16:19:49Z</dc:date>
    </item>
    <item>
      <title>Re: rename a variable level</title>
      <link>https://communities.sas.com/t5/SAS-Programming/rename-a-variable-level/m-p/984227#M379680</link>
      <description>&lt;P&gt;That is what I wanted, thank you so much Tom!&lt;/P&gt;</description>
      <pubDate>Fri, 27 Feb 2026 16:39:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/rename-a-variable-level/m-p/984227#M379680</guid>
      <dc:creator>palolix</dc:creator>
      <dc:date>2026-02-27T16:39:44Z</dc:date>
    </item>
    <item>
      <title>Re: rename a variable level</title>
      <link>https://communities.sas.com/t5/SAS-Programming/rename-a-variable-level/m-p/984228#M379681</link>
      <description>&lt;P&gt;Great, thank you very much!&lt;/P&gt;</description>
      <pubDate>Fri, 27 Feb 2026 16:40:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/rename-a-variable-level/m-p/984228#M379681</guid>
      <dc:creator>palolix</dc:creator>
      <dc:date>2026-02-27T16:40:13Z</dc:date>
    </item>
    <item>
      <title>Re: rename variable level</title>
      <link>https://communities.sas.com/t5/SAS-Programming/rename-a-variable-level/m-p/984229#M379682</link>
      <description>&lt;P&gt;Thank you Ksharp!&lt;/P&gt;</description>
      <pubDate>Fri, 27 Feb 2026 16:40:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/rename-a-variable-level/m-p/984229#M379682</guid>
      <dc:creator>palolix</dc:creator>
      <dc:date>2026-02-27T16:40:36Z</dc:date>
    </item>
  </channel>
</rss>

