<?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: New variable coding problem with if/then/else statement in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/New-variable-coding-problem-with-if-then-else-statement/m-p/687281#M24525</link>
    <description>&lt;P&gt;To visualize your problem, I added empty lines:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data data1;
set data0;

if income&amp;lt;25000 then ses='Q1';

if income&amp;lt;50000&amp;gt;=25000 then ses='Q2';

if income&amp;lt;80000&amp;gt;=50000 then ses='Q3';

if income&amp;lt;130000&amp;gt;=80000 then ses='Q4';

if income&amp;gt;=130000
then ses='Q5';
else sestatus=' ';

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The last IF-THEN-ELSE will code &lt;EM&gt;all&lt;/EM&gt; incomes less than 130000 as missing.&lt;/P&gt;</description>
    <pubDate>Mon, 28 Sep 2020 17:07:26 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2020-09-28T17:07:26Z</dc:date>
    <item>
      <title>New variable coding problem with if/then/else statement</title>
      <link>https://communities.sas.com/t5/New-SAS-User/New-variable-coding-problem-with-if-then-else-statement/m-p/687275#M24523</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I am trying to recode the variable "income" (numeric) into 5 stratified categories (new stratified variable = ses). Although my output demonstrates that only one category ("Q5") is being coded.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a problem with my if/then/else statements?&lt;/P&gt;&lt;P&gt;data data1;&lt;/P&gt;&lt;P&gt;set data0;&lt;/P&gt;&lt;P&gt;if income&amp;lt;25000 then ses='Q1';&lt;BR /&gt;if income&amp;lt;50000&amp;gt;=25000 then ses='Q2';&lt;BR /&gt;if income&amp;lt;80000&amp;gt;=50000 then ses='Q3';&lt;BR /&gt;if income&amp;lt;130000&amp;gt;=80000 then ses='Q4';&lt;BR /&gt;if income&amp;gt;=130000 then ses='Q5';&lt;BR /&gt;else sestatus=' ';&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 16:50:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/New-variable-coding-problem-with-if-then-else-statement/m-p/687275#M24523</guid>
      <dc:creator>njgrubic</dc:creator>
      <dc:date>2020-09-28T16:50:35Z</dc:date>
    </item>
    <item>
      <title>Re: New variable coding problem with if/then/else statement</title>
      <link>https://communities.sas.com/t5/New-SAS-User/New-variable-coding-problem-with-if-then-else-statement/m-p/687279#M24524</link>
      <description>&lt;P&gt;This is how it should be coded.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data data1;

set data0;

if income &amp;lt; 25000 then ses='Q1';
else if  25000 &amp;lt; income &amp;lt;= 50000 then ses='Q2';
else if  50000 &amp;lt; income &amp;lt;= 80000 then ses='Q3';
else if 80000 &amp;lt; income &amp;lt; 130000 then ses='Q4';
else if income &amp;gt;= 130000 then ses='Q5';
else sestatus=' ';

run;&lt;/CODE&gt;&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Note that if the income variable is missing it will get coded to Q1 with this logic. &lt;/STRONG&gt;If you want to account for that you should do it as the first step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data data1;

set data0;
if missing(income) then call missing(ses);
else if income &amp;lt; 25000 then ses='Q1';
else if  25000 &amp;lt; income &amp;lt;= 50000 then ses='Q2';
else if  50000 &amp;lt; income &amp;lt;= 80000 then ses='Q3';
else if 80000 &amp;lt; income &amp;lt; 130000 then ses='Q4';
else if income &amp;gt;= 130000 then ses='Q5';
else sestatus=' ';

run;&amp;nbsp;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/349601"&gt;@njgrubic&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I am trying to recode the variable "income" (numeric) into 5 stratified categories (new stratified variable = ses). Although my output demonstrates that only one category ("Q5") is being coded.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there a problem with my if/then/else statements?&lt;/P&gt;
&lt;P&gt;data data1;&lt;/P&gt;
&lt;P&gt;set data0;&lt;/P&gt;
&lt;P&gt;if income&amp;lt;25000 then ses='Q1';&lt;BR /&gt;if income&amp;lt;50000&amp;gt;=25000 then ses='Q2';&lt;BR /&gt;if income&amp;lt;80000&amp;gt;=50000 then ses='Q3';&lt;BR /&gt;if income&amp;lt;130000&amp;gt;=80000 then ses='Q4';&lt;BR /&gt;if income&amp;gt;=130000 then ses='Q5';&lt;BR /&gt;else sestatus=' ';&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 16:58:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/New-variable-coding-problem-with-if-then-else-statement/m-p/687279#M24524</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-09-28T16:58:26Z</dc:date>
    </item>
    <item>
      <title>Re: New variable coding problem with if/then/else statement</title>
      <link>https://communities.sas.com/t5/New-SAS-User/New-variable-coding-problem-with-if-then-else-statement/m-p/687281#M24525</link>
      <description>&lt;P&gt;To visualize your problem, I added empty lines:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data data1;
set data0;

if income&amp;lt;25000 then ses='Q1';

if income&amp;lt;50000&amp;gt;=25000 then ses='Q2';

if income&amp;lt;80000&amp;gt;=50000 then ses='Q3';

if income&amp;lt;130000&amp;gt;=80000 then ses='Q4';

if income&amp;gt;=130000
then ses='Q5';
else sestatus=' ';

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The last IF-THEN-ELSE will code &lt;EM&gt;all&lt;/EM&gt; incomes less than 130000 as missing.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 17:07:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/New-variable-coding-problem-with-if-then-else-statement/m-p/687281#M24525</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-09-28T17:07:26Z</dc:date>
    </item>
    <item>
      <title>Re: New variable coding problem with if/then/else statement</title>
      <link>https://communities.sas.com/t5/New-SAS-User/New-variable-coding-problem-with-if-then-else-statement/m-p/687282#M24526</link>
      <description>Thanks reeza,&lt;BR /&gt;I ended up adding in 0 to the "Q1" classificaiton to ensure I was not including 'blank' observations.&lt;BR /&gt;&lt;BR /&gt;if 0 &amp;lt; income &amp;lt; 25000 then ses='Q1';&lt;BR /&gt;else if 25000 &amp;lt; income &amp;lt;= 50000 then ses='Q2';&lt;BR /&gt;else if 50000 &amp;lt; income &amp;lt;= 80000 then ses='Q3';&lt;BR /&gt;else if 80000 &amp;lt; income &amp;lt; 130000 then ses='Q4';&lt;BR /&gt;else if income &amp;gt;= 130000 then ses='Q5';&lt;BR /&gt;else ses=' ';&lt;BR /&gt;</description>
      <pubDate>Mon, 28 Sep 2020 17:08:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/New-variable-coding-problem-with-if-then-else-statement/m-p/687282#M24526</guid>
      <dc:creator>njgrubic</dc:creator>
      <dc:date>2020-09-28T17:08:47Z</dc:date>
    </item>
    <item>
      <title>Re: New variable coding problem with if/then/else statement</title>
      <link>https://communities.sas.com/t5/New-SAS-User/New-variable-coding-problem-with-if-then-else-statement/m-p/687283#M24527</link>
      <description>Are you sure all income must be positive? &lt;BR /&gt;</description>
      <pubDate>Mon, 28 Sep 2020 17:09:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/New-variable-coding-problem-with-if-then-else-statement/m-p/687283#M24527</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-09-28T17:09:57Z</dc:date>
    </item>
    <item>
      <title>Re: New variable coding problem with if/then/else statement</title>
      <link>https://communities.sas.com/t5/New-SAS-User/New-variable-coding-problem-with-if-then-else-statement/m-p/687284#M24528</link>
      <description>&lt;P&gt;The proper approach to issues like this is to create a value format with ranges, and assign it to the income variable when you use it as CLASS variable in analytic procedures.&lt;/P&gt;
&lt;P&gt;Even when you create a new variable, using the format in a PUT statement makes for much cleaner code.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 17:13:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/New-variable-coding-problem-with-if-then-else-statement/m-p/687284#M24528</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-09-28T17:13:28Z</dc:date>
    </item>
  </channel>
</rss>

