<?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: Recoding in a new variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Recoding-in-a-new-variable/m-p/369726#M88303</link>
    <description>&lt;P&gt;Are you trying to create 1 new variable or 5 new variables?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you're doing 1, why not make them all ELSE IF after the first condition.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Otherwise, I think you'll need to explain the logic in more detail and with sample data.&lt;/P&gt;</description>
    <pubDate>Thu, 22 Jun 2017 22:18:46 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2017-06-22T22:18:46Z</dc:date>
    <item>
      <title>Recoding in a new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recoding-in-a-new-variable/m-p/369721#M88300</link>
      <description>&lt;P&gt;I am trying to create one nominal variable w/ 6&amp;nbsp;categories from 3 existing variables. I want values from 0-5 in the new variable (combo_expo).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;With the syntax below, the last IF-THEN-ELSE statement overwrites the previous statements. The values are all 0 or 5. This seems pretty straight forward, but I haven't been able to resolve it w/ my own methods. Thanks.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;* Never users;&lt;BR /&gt; IF ever_used = 2 THEN combo_expo = 1;&lt;BR /&gt; ELSE IF ever_used NE 2 THEN combo_expo = 0;&lt;BR /&gt; &lt;BR /&gt; * Past users. Not in the past 30 days;&lt;BR /&gt; IF last_used GE 30 THEN combo_expo = 2;&lt;BR /&gt; ELSE combo_expo = 0;&lt;BR /&gt; &lt;BR /&gt; * Current, light users;&lt;BR /&gt; IF days_use_month LE 4THEN combo_expo = 3;&lt;BR /&gt; ELSE combo_expo = 0;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;* Current, heavy users;&lt;BR /&gt; IF days_use_month GE 5 THEN combo_expo = 4;&lt;BR /&gt; ELSE combo_expo = 0;&lt;BR /&gt; &lt;BR /&gt; * Chronic users, monthly x 1 year;&lt;BR /&gt; IF monthly_yr = 1 THEN combo_expo = 5;&lt;BR /&gt; ELSE combo_expo = 0;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Jun 2017 22:01:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recoding-in-a-new-variable/m-p/369721#M88300</guid>
      <dc:creator>_maldini_</dc:creator>
      <dc:date>2017-06-22T22:01:48Z</dc:date>
    </item>
    <item>
      <title>Re: Recoding in a new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recoding-in-a-new-variable/m-p/369726#M88303</link>
      <description>&lt;P&gt;Are you trying to create 1 new variable or 5 new variables?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you're doing 1, why not make them all ELSE IF after the first condition.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Otherwise, I think you'll need to explain the logic in more detail and with sample data.&lt;/P&gt;</description>
      <pubDate>Thu, 22 Jun 2017 22:18:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recoding-in-a-new-variable/m-p/369726#M88303</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-06-22T22:18:46Z</dc:date>
    </item>
    <item>
      <title>Re: Recoding in a new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recoding-in-a-new-variable/m-p/369734#M88309</link>
      <description>&lt;P&gt;You probably need to think through the plan a little more. &amp;nbsp;You actually have 32 categories, so 0-5 won't be enough. &amp;nbsp;The&amp;nbsp;logic of the variables may rule out some of the combinations, but it's a bad idea to rule them out without having the data tell you whether or not they exist. &amp;nbsp;For example, the data might indicate that both&amp;nbsp;"never a user" and "current light user" are both true. &amp;nbsp;Here's one train of thought to get you started:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;combo_expo='00000';&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;IF ever_used = 2 THEN substr(combo_expo, 5, 1) = '1';&lt;BR /&gt;IF last_used GE 30 THEN substr(combo_expo, 4, 1) = '2';&lt;BR /&gt;IF days_use_month LE 4 THEN substr(combo_expo, 3, 1) = '3';&lt;BR /&gt;IF days_use_month GE 5 THEN substr(combo_expo, 2, 1) = '4';&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;IF monthly_yr = 1 THEN substr(combo_expo, 1, 1) = '5';&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;You can always change the order if you would like. &amp;nbsp;Then run a PROC FREQ on combo_expo to get a picture of what your data contains.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Jun 2017 23:01:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recoding-in-a-new-variable/m-p/369734#M88309</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-06-22T23:01:44Z</dc:date>
    </item>
    <item>
      <title>Re: Recoding in a new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recoding-in-a-new-variable/m-p/369737#M88312</link>
      <description>&lt;P&gt;Like this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  COMBO_EXPO=ifn(MONTHLY_YR     eq  1, 5   %* Chronic users, monthly x 1 year    ;
            ,ifn(DAYS_USE_MONTH ge  5, 4   %* Current, heavy users               ;
            ,ifn(DAYS_USE_MONTH le  4, 3   %* Current, light users               ;
            ,ifn(LAST_USED      ge 30, 2   %* Past users. Not in the past 30 days;
            ,ifn(EVER_USED      eq  2, 1   %* Never users                        ;
            ,                          0)))));
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Jun 2017 23:46:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recoding-in-a-new-variable/m-p/369737#M88312</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2017-06-22T23:46:38Z</dc:date>
    </item>
    <item>
      <title>Re: Recoding in a new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recoding-in-a-new-variable/m-p/369797#M88330</link>
      <description>&lt;P&gt;If you only want the first condition then maybe a select statement:&lt;/P&gt;
&lt;PRE&gt;data want;
  set have;
  select;
    when(ever_used=2) combo_expo=1;
    when(last_used &amp;gt;= 30) combo_expo=2;
    ...
    otherwise combo_expo=0;
  end;
run;
   &lt;/PRE&gt;</description>
      <pubDate>Fri, 23 Jun 2017 08:19:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recoding-in-a-new-variable/m-p/369797#M88330</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-06-23T08:19:03Z</dc:date>
    </item>
    <item>
      <title>Re: Recoding in a new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recoding-in-a-new-variable/m-p/369971#M88365</link>
      <description>&lt;P&gt;I am trying to create 1 new variable. I added ELSE IF statements. My latest syntax is below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I get different results when I change the order of the IF-THE-ELSE statements.&amp;nbsp;This seems like a lack of understanding on my part as to how SAS processes these conditions in the IF-THE-ELSE statements.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have attached the data and a copy of my results I get w/ the syntax below. In this order, the&amp;nbsp;IF-THE-ELSE statements produce the correct counts, except for monthly_yr, which has fewer counts than it should (518 v. 953).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks again for the assistance.&lt;/P&gt;
&lt;PRE&gt;	* Current, light users;
    IF days_use_month LE 4 AND NOT MISSING (days_use_month) THEN combo_expo = 3;

    * Current, heavy users;
    ELSE IF days_use_month GE 5 AND days_use_month LE 30 AND NOT MISSING (days_use_month) THEN combo_expo = 4;

	* Never users;
    ELSE IF ever_used = 2 THEN combo_expo = 1;
    
    * Chronic users, monthly x 1 year;
    ELSE IF monthly_yr = 1 THEN combo_expo = 5;
    
    * Past users. Not in the past 30 days;
    ELSE IF last_used GE 30 THEN combo_expo = 2;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/9742i870D51CF4E763014/image-size/original?v=1.0&amp;amp;px=-1" border="0" alt="PROC FREQ.jpg" title="PROC FREQ.jpg" /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Jun 2017 16:02:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recoding-in-a-new-variable/m-p/369971#M88365</guid>
      <dc:creator>_maldini_</dc:creator>
      <dc:date>2017-06-23T16:02:20Z</dc:date>
    </item>
    <item>
      <title>Re: Recoding in a new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recoding-in-a-new-variable/m-p/370016#M88375</link>
      <description>&lt;P&gt;I think you need to read through&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;&amp;nbsp;post again. It sounds like you haven't quite thought through all your categories that's the issue.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Jun 2017 17:11:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recoding-in-a-new-variable/m-p/370016#M88375</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-06-23T17:11:20Z</dc:date>
    </item>
    <item>
      <title>Re: Recoding in a new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recoding-in-a-new-variable/m-p/370017#M88376</link>
      <description>&lt;P&gt;I think you need to read through&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;&amp;nbsp;post again. It sounds like you haven't quite thought through all your categories that's the issue.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Jun 2017 17:11:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recoding-in-a-new-variable/m-p/370017#M88376</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-06-23T17:11:23Z</dc:date>
    </item>
    <item>
      <title>Re: Recoding in a new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recoding-in-a-new-variable/m-p/370151#M88404</link>
      <description>&lt;P&gt;You may want to run some code like this against your data to see that actual combinations that you have.&lt;/P&gt;
&lt;PRE&gt;proc freq data=have;
  tables ever_used *last_used *  days_use_month * monthly_yr *combo_expo/ list missing;
run;&lt;/PRE&gt;
&lt;P&gt;Which may reveal that some of the values you expect to come from monthly_yr are being appropriated by a different set of variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Jun 2017 20:13:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recoding-in-a-new-variable/m-p/370151#M88404</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-06-23T20:13:12Z</dc:date>
    </item>
  </channel>
</rss>

