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 (November 2006, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Mon, 27 Nov 2006 14:09:27 -0500
Reply-To:     Jack Clark <JClark@CHPDM.UMBC.EDU>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Jack Clark <JClark@CHPDM.UMBC.EDU>
Subject:      Re: is there another way doing it
Comments: To: SAS_learner <proccontents@GMAIL.COM>
Content-Type: text/plain

SAS_learner,

Another option is the SELECT statement. It is usually recommended as more efficient when you have more than a handful of IF-THEN choices. I don't know if that holds true when the select is based on the value of more than one variable.

One thing you could do for improved efficiency to the example you provided is add the ELSE statement to all IF-THEN checks after the first one. Each IF-THEN you provided is mutually exclusive (based on the values of parnam1c you are checking). Therefore, once an observation meets one of the IF-THEN conditions, there is no need to check the others below it.

if parnam1c='BAS' and upcase(preunt1c)='%' and ( LABRSL1N> 6) then output; ELSE if parnam1c='EOS' and upcase(preunt1c)='%' and ( LABRSL1N> 10) then output; ELSE if parnam1c='HGB' and upcase(preunt1c)='G/L' and (LABRSL1N<100 or LABRSL1N>200) then output; ELSE if parnam1c='HCT' and upcase(preunt1c)='1' and (LABRSL1N<0.3 or LABRSL1N>0.6) then output; ELSE if parnam1c='LYM' and upcase(preunt1c)='%' and (LABRSL1N<10 or LABRSL1N> 60) then output; ELSE if parnam1c='MON' and upcase(preunt1c)='%' and ( LABRSL1N> 20) then output;

I was taught to order the IF-THEN choices in the program in the order in which they most likely will occur in your data (if you have an estimate of this ahead of time). So if you know that 70% of your input observations have a value of 'BAS' for parnam1c, you would put that check first, and so on. If you were to put the check for 'BAS' last, you would have to go through each of the IF-THEN-ELSE statements for 70% of your observations.

Jack Clark Research Analyst Center for Health Program Development and Management University of Maryland, Baltimore County

-----Original Message----- From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of SAS_learner Sent: Monday, November 27, 2006 12:26 PM To: SAS-L@LISTSERV.UGA.EDU Subject: is there another way doing it

Hello guys for a listing I need to do something like this for couple of different values of Parnam1c, What I am looking is there a better way to dot it or is this only way to do it

if parnam1c='BAS' and upcase(preunt1c)='%' and ( LABRSL1N> 6) then output; if parnam1c='EOS' and upcase(preunt1c)='%' and ( LABRSL1N> 10) then output; if parnam1c='HGB' and upcase(preunt1c)='G/L' and (LABRSL1N<100 or LABRSL1N>200) then output; if parnam1c='HCT' and upcase(preunt1c)='1' and (LABRSL1N<0.3 or LABRSL1N>0.6) then output; if parnam1c='LYM' and upcase(preunt1c)='%' and (LABRSL1N<10 or LABRSL1N> 60) then output; if parnam1c='MON' and upcase(preunt1c)='%' and ( LABRSL1N> 20) then output;

thanks


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