<?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 If-then/else-if/else statements in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/If-then-else-if-else-statements/m-p/57142#M15942</link>
    <description>Hi,&lt;BR /&gt;
   I am trying to understand this, but always not getting to the key.Can any one help me with this..&lt;BR /&gt;
&lt;BR /&gt;
/********PROGRAM********/&lt;BR /&gt;
data 'C:\MySASLib\Old';&lt;BR /&gt;
 infile ' C:\MYSAS\groups.dat';&lt;BR /&gt;
 input  Name $ 1-5 group  6;&lt;BR /&gt;
run;&lt;BR /&gt;
data New;&lt;BR /&gt;
set 'C:\MySASLib\Old';&lt;BR /&gt;
 if group = . then new_grp = 'UNKNOWN';&lt;BR /&gt;
 else if group =1 then new_grp ='LOWER';&lt;BR /&gt;
 else if group=2 or 3 then new-grp='MEDIUM';&lt;BR /&gt;
 else new_grp= 'HIGHEST';&lt;BR /&gt;
run;&lt;BR /&gt;
proc print data= New;&lt;BR /&gt;
run;&lt;BR /&gt;
/***********END OF PROGRAM*************/&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Q:-Now when I run this , what how is the value for new_grp variable only UNKNOWN, LOWER and MEDIUM??? Why isn't it considering the 'HIGH' value????&lt;BR /&gt;
Below is the raw data file:groups.dat&lt;BR /&gt;
Amie 1&lt;BR /&gt;
Dolly  2&lt;BR /&gt;
John  2&lt;BR /&gt;
Eddie 3&lt;BR /&gt;
Sue   4&lt;BR /&gt;
Kieth 6&lt;BR /&gt;
henry .&lt;BR /&gt;
Jack  1&lt;B&gt;&lt;/B&gt;&lt;BR /&gt;
&lt;BR /&gt;
It would be really helpful, if any one cud reply to this as soon as possible.&lt;BR /&gt;
Thanks.</description>
    <pubDate>Mon, 27 Oct 2008 00:14:30 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2008-10-27T00:14:30Z</dc:date>
    <item>
      <title>If-then/else-if/else statements</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/If-then-else-if-else-statements/m-p/57142#M15942</link>
      <description>Hi,&lt;BR /&gt;
   I am trying to understand this, but always not getting to the key.Can any one help me with this..&lt;BR /&gt;
&lt;BR /&gt;
/********PROGRAM********/&lt;BR /&gt;
data 'C:\MySASLib\Old';&lt;BR /&gt;
 infile ' C:\MYSAS\groups.dat';&lt;BR /&gt;
 input  Name $ 1-5 group  6;&lt;BR /&gt;
run;&lt;BR /&gt;
data New;&lt;BR /&gt;
set 'C:\MySASLib\Old';&lt;BR /&gt;
 if group = . then new_grp = 'UNKNOWN';&lt;BR /&gt;
 else if group =1 then new_grp ='LOWER';&lt;BR /&gt;
 else if group=2 or 3 then new-grp='MEDIUM';&lt;BR /&gt;
 else new_grp= 'HIGHEST';&lt;BR /&gt;
run;&lt;BR /&gt;
proc print data= New;&lt;BR /&gt;
run;&lt;BR /&gt;
/***********END OF PROGRAM*************/&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Q:-Now when I run this , what how is the value for new_grp variable only UNKNOWN, LOWER and MEDIUM??? Why isn't it considering the 'HIGH' value????&lt;BR /&gt;
Below is the raw data file:groups.dat&lt;BR /&gt;
Amie 1&lt;BR /&gt;
Dolly  2&lt;BR /&gt;
John  2&lt;BR /&gt;
Eddie 3&lt;BR /&gt;
Sue   4&lt;BR /&gt;
Kieth 6&lt;BR /&gt;
henry .&lt;BR /&gt;
Jack  1&lt;B&gt;&lt;/B&gt;&lt;BR /&gt;
&lt;BR /&gt;
It would be really helpful, if any one cud reply to this as soon as possible.&lt;BR /&gt;
Thanks.</description>
      <pubDate>Mon, 27 Oct 2008 00:14:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/If-then-else-if-else-statements/m-p/57142#M15942</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-10-27T00:14:30Z</dc:date>
    </item>
    <item>
      <title>Re: If-then/else-if/else statements</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/If-then-else-if-else-statements/m-p/57143#M15943</link>
      <description>What happens if you change the last option from 'else' to 'else if group &amp;gt; 3' ?</description>
      <pubDate>Mon, 27 Oct 2008 01:19:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/If-then-else-if-else-statements/m-p/57143#M15943</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-10-27T01:19:53Z</dc:date>
    </item>
    <item>
      <title>Re: If-then/else-if/else statements</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/If-then-else-if-else-statements/m-p/57144#M15944</link>
      <description>Hi SAS_Learner&lt;BR /&gt;
&lt;BR /&gt;
The statement&lt;BR /&gt;
else if group=2 or 3 then new-grp='MEDIUM';&lt;BR /&gt;
always resolves to TRUE.&lt;BR /&gt;
&lt;BR /&gt;
You could write:&lt;BR /&gt;
else if group in(2,3) then new-grp='MEDIUM';&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Another possibility would be to create a format (code not tested):&lt;BR /&gt;
&lt;BR /&gt;
proc format;&lt;BR /&gt;
  value grpname&lt;BR /&gt;
     1  ='UNKNOWN'&lt;BR /&gt;
     2,3='LOWER'&lt;BR /&gt;
     &amp;gt;3 ='HIGHEST'&lt;BR /&gt;
   other='UNKNOWN'&lt;BR /&gt;
  ;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data 'C:\MySASLib\Old';&lt;BR /&gt;
infile ' C:\MYSAS\groups.dat';&lt;BR /&gt;
input Name $ 1-5 group 6;&lt;BR /&gt;
run;&lt;BR /&gt;
data New;&lt;BR /&gt;
set 'C:\MySASLib\Old';&lt;BR /&gt;
new_grp =put(group,grpname.);&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc print data= New;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
HTH&lt;BR /&gt;
Patrick</description>
      <pubDate>Mon, 27 Oct 2008 06:43:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/If-then-else-if-else-statements/m-p/57144#M15944</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2008-10-27T06:43:57Z</dc:date>
    </item>
    <item>
      <title>Re: If-then/else-if/else statements</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/If-then-else-if-else-statements/m-p/57145#M15945</link>
      <description>Hi Patrick,&lt;BR /&gt;
          I do agree that 'or' always resolves for TRUE, but then what about the  groups higher than 3. Like for instance even for group 6 , it is showing medium.????&lt;BR /&gt;
Of course I can get the correct , desired answer in many ways(which also includes the one u said PROC FORMAT).&lt;BR /&gt;
But I wanted to know whats happening with this code (which I sent)??&lt;BR /&gt;
Is it bcoz of using the 'or'  operator , it no more considers any other values????&lt;BR /&gt;
&lt;BR /&gt;
Thanks,&lt;BR /&gt;
SAS_Learner</description>
      <pubDate>Mon, 27 Oct 2008 14:51:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/If-then-else-if-else-statements/m-p/57145#M15945</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-10-27T14:51:05Z</dc:date>
    </item>
    <item>
      <title>Re: If-then/else-if/else statements</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/If-then-else-if-else-statements/m-p/57146#M15946</link>
      <description>I think you're missing the point here. Since SAS logic says that everything except the value of 0 resolves to TRUE, your OR 3 will always be TRUE, and therefore it will never go to your last ELSE statment, that will assign according to higher values than 2. So again, if you want your program to work, simply change your if statment to &lt;I&gt;group in(2,3)&lt;/I&gt;.&lt;BR /&gt;
&lt;BR /&gt;
/Linus</description>
      <pubDate>Mon, 27 Oct 2008 15:48:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/If-then-else-if-else-statements/m-p/57146#M15946</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2008-10-27T15:48:59Z</dc:date>
    </item>
    <item>
      <title>Re: If-then/else-if/else statements</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/If-then-else-if-else-statements/m-p/57147#M15947</link>
      <description>There is a coding problem here.  You can't use group=2 or 3.  One needs to use group=2 or group=3.  Code below works as expected - same as if group in (2,3) in reply above.&lt;BR /&gt;
&lt;BR /&gt;
if group = . then new_grp = 'UNKNOWN';                                                                                                  &lt;BR /&gt;
else if group =1 then new_grp ='LOWER';                                                                                                 &lt;BR /&gt;
else if group=2 or group=3 then new_grp='MEDIUM';                                                                                       &lt;BR /&gt;
else new_grp= 'HIGHEST';</description>
      <pubDate>Mon, 27 Oct 2008 15:59:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/If-then-else-if-else-statements/m-p/57147#M15947</guid>
      <dc:creator>Bill</dc:creator>
      <dc:date>2008-10-27T15:59:16Z</dc:date>
    </item>
    <item>
      <title>Re: If-then/else-if/else statements</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/If-then-else-if-else-statements/m-p/57148#M15948</link>
      <description>YEAH, this is what I was expecting ...&lt;BR /&gt;
Thank You Linus H.&lt;BR /&gt;
That makes a  lot of sense.&lt;BR /&gt;
&lt;BR /&gt;
SAS_Learner</description>
      <pubDate>Mon, 27 Oct 2008 22:24:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/If-then-else-if-else-statements/m-p/57148#M15948</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-10-27T22:24:32Z</dc:date>
    </item>
    <item>
      <title>Re: If-then/else-if/else statements</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/If-then-else-if-else-statements/m-p/57149#M15949</link>
      <description>Bill,&lt;BR /&gt;
    I don't think there is any coding problem, because I wanted to know if I write in this way , how would SAS react.. and one of our frnds Linus H (as u can see other replies) gave the explanation to this.&lt;BR /&gt;
But what you said , gives the correct output though.&lt;BR /&gt;
&lt;BR /&gt;
Thanks,&lt;BR /&gt;
SAS_Learner</description>
      <pubDate>Mon, 27 Oct 2008 22:30:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/If-then-else-if-else-statements/m-p/57149#M15949</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-10-27T22:30:50Z</dc:date>
    </item>
  </channel>
</rss>

