<?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: using an &amp;quot;in&amp;quot; statement to rename a categorical variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/using-an-quot-in-quot-statement-to-rename-a-categorical-variable/m-p/424170#M104420</link>
    <description>&lt;P&gt;Your code works fine when i tested:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data have;&lt;/STRONG&gt;&lt;BR /&gt;do comorb_comp=1 to 11;&lt;BR /&gt;output;&lt;BR /&gt;end;&lt;BR /&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data want;&lt;/STRONG&gt;&lt;BR /&gt;set have;&lt;BR /&gt;elix_category=0;&lt;BR /&gt;if comorb_comp in (1, 2, 3, 4) then elix_category=1;&lt;BR /&gt;if comorb_comp in (5, 6, 7, 8, 9) then elix_category=2;&lt;BR /&gt;if comorb_comp in (10, 11) then elix_category=3;&lt;BR /&gt;if comorb_comp=. then elix_category=.;&lt;BR /&gt;&lt;STRONG&gt;run;&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;You could rather use "else if" as your conditions are mutual:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data want;&lt;/STRONG&gt;&lt;BR /&gt;set have;&lt;BR /&gt;elix_category=0;&lt;BR /&gt;if comorb_comp in (1, 2, 3, 4) then elix_category=1;&lt;BR /&gt;&lt;STRONG&gt;else if&lt;/STRONG&gt; comorb_comp in (5, 6, 7, 8, 9) then elix_category=2;&lt;BR /&gt;&lt;STRONG&gt;else if&lt;/STRONG&gt; comorb_comp in (10, 11) then elix_category=3;&lt;BR /&gt;&lt;STRONG&gt;else if&lt;/STRONG&gt; comorb_comp=. then elix_category=.;&lt;BR /&gt;&lt;STRONG&gt;run;&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 31 Dec 2017 18:08:08 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2017-12-31T18:08:08Z</dc:date>
    <item>
      <title>using an "in" statement to rename a categorical variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/using-an-quot-in-quot-statement-to-rename-a-categorical-variable/m-p/424169#M104419</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm using SAS 9.4 full edition through a virtual desktop. There is an integer variable that goes 1-11 and I'm trying to categorize it into 4 categories using an "in" statement but it's not working. Can someone fix my code below?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Laura&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;elix_category=0;
if comorb_comp in(1, 2, 3, 4) then elix_category=1;
if comorb_comp in(5, 6, 7, 8, 9) then elix_category=2;
if comorb_comp in(10, 11) then elix_category=3;
if comorb_comp=. then elix_category=.;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 31 Dec 2017 17:39:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/using-an-quot-in-quot-statement-to-rename-a-categorical-variable/m-p/424169#M104419</guid>
      <dc:creator>lmyers2</dc:creator>
      <dc:date>2017-12-31T17:39:37Z</dc:date>
    </item>
    <item>
      <title>Re: using an "in" statement to rename a categorical variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/using-an-quot-in-quot-statement-to-rename-a-categorical-variable/m-p/424170#M104420</link>
      <description>&lt;P&gt;Your code works fine when i tested:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data have;&lt;/STRONG&gt;&lt;BR /&gt;do comorb_comp=1 to 11;&lt;BR /&gt;output;&lt;BR /&gt;end;&lt;BR /&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data want;&lt;/STRONG&gt;&lt;BR /&gt;set have;&lt;BR /&gt;elix_category=0;&lt;BR /&gt;if comorb_comp in (1, 2, 3, 4) then elix_category=1;&lt;BR /&gt;if comorb_comp in (5, 6, 7, 8, 9) then elix_category=2;&lt;BR /&gt;if comorb_comp in (10, 11) then elix_category=3;&lt;BR /&gt;if comorb_comp=. then elix_category=.;&lt;BR /&gt;&lt;STRONG&gt;run;&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;You could rather use "else if" as your conditions are mutual:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data want;&lt;/STRONG&gt;&lt;BR /&gt;set have;&lt;BR /&gt;elix_category=0;&lt;BR /&gt;if comorb_comp in (1, 2, 3, 4) then elix_category=1;&lt;BR /&gt;&lt;STRONG&gt;else if&lt;/STRONG&gt; comorb_comp in (5, 6, 7, 8, 9) then elix_category=2;&lt;BR /&gt;&lt;STRONG&gt;else if&lt;/STRONG&gt; comorb_comp in (10, 11) then elix_category=3;&lt;BR /&gt;&lt;STRONG&gt;else if&lt;/STRONG&gt; comorb_comp=. then elix_category=.;&lt;BR /&gt;&lt;STRONG&gt;run;&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 31 Dec 2017 18:08:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/using-an-quot-in-quot-statement-to-rename-a-categorical-variable/m-p/424170#M104420</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2017-12-31T18:08:08Z</dc:date>
    </item>
    <item>
      <title>Re: using an "in" statement to rename a categorical variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/using-an-quot-in-quot-statement-to-rename-a-categorical-variable/m-p/424374#M104500</link>
      <description>&lt;P&gt;The SELECT block works better than If/than/else for more than a couple of values when examining a single variable:&lt;/P&gt;
&lt;PRE&gt;select (comorb_comp);
   when (1, 2, 3, 4)  elix_category=1;
   when (5, 6, 7, 8, 9)  elix_category=2;
   when (10, 11)  elix_category=3;
   when (.)  elix_category=.;
   otherwise elix_category=0;
end;&lt;/PRE&gt;
&lt;P&gt;The When lists the values of the variable on the select statement to evaluate. If you want to do multiple things when a given value is selected you can use a do /end construct.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The otherwise is the instruction when none of the listed values in all of the when statements are found.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I had a large number of variables with the same requirement I might consider a custom informat.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jan 2018 17:06:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/using-an-quot-in-quot-statement-to-rename-a-categorical-variable/m-p/424374#M104500</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-01-02T17:06:15Z</dc:date>
    </item>
  </channel>
</rss>

