LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (March 2005, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Sun, 20 Mar 2005 11:48:55 -0500
Reply-To:     "Howard Schreier <hs AT dc-sug DOT org>" <nospam@HOWLES.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         "Howard Schreier <hs AT dc-sug DOT org>" <nospam@HOWLES.COM>
Subject:      Re: else if and if ? why they give different results ?


sets up mutually exclusive actions. There can be any number if ELSE IF statements in the "sandwich".

On the other hand, with

IF ... IF ... ELSE

the ELSE relates only to the immediately preceding IF. So ActorI and ActorII will trigger both the first IF and the ELSE.

A SELECT structure can be used instead, and may be clearer.

On Sat, 19 Mar 2005 10:18:29 -0800, sawir yakup <ysawir@YAHOO.COM> wrote:

>Can someone explain why the codes below give different >outputs when using if and else if statement ? > >data a; >input jobcode $ count; >cards; >ActorI 2 >ActorII 3 >ActorIII 3 >ActorI 3 >. 4 >ActorIII 2 >ActorI 1 >ActorII 1 >ActorIII 2 >; >/*proc freq; table jobcode; run; */ > >/* this DATA step gives the right output */ >data b; set a; > if jobcode in ('ActorI', 'ActorII') then >joblevel='Beginner'; > else if jobcode = 'ActorIII' then >joblevel='Advanced'; > else joblevel='Unknown'; > run; > >/* this DATA step gives the wrong output, why ? */ >data c; set a; > if jobcode in ('ActorI', 'ActorII') then >joblevel='Beginner'; > if jobcode = 'ActorIII' then joblevel='Advanced'; > else joblevel='Unknown'; > run; >proc print data=b; title "Data B"; >proc print data=c; title "Data C"; run; > > > >__________________________________ >Do you Yahoo!? >Yahoo! Small Business - Try our new resources site! >

Back to: Top of message | Previous page | Main SAS-L page