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 (October 2006, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Tue, 24 Oct 2006 11:21:03 -0400
Reply-To:     Sigurd Hermansen <HERMANS1@WESTAT.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Sigurd Hermansen <HERMANS1@WESTAT.COM>
Subject:      Re: do loop
Comments: To: phillyj <jessica.donato@gmail.com>
In-Reply-To:  <1161699923.227597.43180@m73g2000cwd.googlegroups.com>
Content-Type: text/plain; charset="US-ASCII"

Phillyj: I do believe it's time for you to check out the Data step SELECT statement or the PROC SQL CASE clause. Both handle mutually exclusive alternatives very nicely. Once you understand the mutually exclusive CASE of program structure, you will also have a better understanding of the a sequence of independent tests. For the latter you will have to determine what to do with what could amount to five different error messages for the same row of data. Since you are creating a dataset of messages, it would likely work well at that stage to put an output statement after an error message assignment in a DO; ... END; block. I'd also recommend including a key to the row of data, the onset date, and perhaps other column values as well. Sig

-----Original Message----- From: owner-sas-l@listserv.uga.edu [mailto:owner-sas-l@listserv.uga.edu] On Behalf Of phillyj Sent: Tuesday, October 24, 2006 10:25 AM To: sas-l@uga.edu Subject: Re: do loop

Thanks for all your suggestions. The problem I am encountering ( after eliminating the else and do statements) is as sas reads through the program, it is not accounting for each condition separately. For example, the first condition alone accounts for 6 observations but when combined with the second statement, it is not picking up any observations. When I run the first three statements together it is only running the last two statements properly and not the first. I would like each 'if' statement to be a separate condition not related to the ones prior. I never encountered this problem with simple if-then statements so am awfully confused why this is happening. Thanks for your suggestions...

Data ERROR; set newdate (where=(AE_ONSET_DATE ne .)); IF year(AE_ONSET_DATE) < 2001 then ErrorMessage='AE ONSET not within study boundaries'; IF AE_ONSET_DATE < dateregistered and dateregistered ne . then ErrorMessage='AE ONSET is before date of randomization'; IF AE_ONSET_DATE > AE_RESOLVED_DATE and AE_RESOLVED_DATE ne . then ErrorMessage='AE ONSET is after AE RESOLVED'; If AE_ONSET_DATE > death AND DEATH NE . then ErrorMessage='AE ONSET is after date of Death'; If AE_ONSET_DATE < mindate AND mindate NE . then ErrorMessage='AE ONSET is before date of start therapy'; run;

Martin Mathis wrote: > Syntactically, the code below looks perfectly valid and error free. > I'd structure it differently for readability but oh well. Where do you

> think you are going wrong and why? > > I'm merely speculating: > > a) Are you confident that all the expected variables are on dataset > "newdate" and are SAS date variables? AE_ONSET_DATE, dateregistered, > death etc. Do they ever satisfy any of the criteria at all? You might > want a catch- all "else" or "else do" at the bottom that says > ErrorMessage="No Error". Or says "else delete;" in lieu of a > conditional "output" statement should you only want error obs in the > ERROR dataset. > > b)Are you asking whether you should be using a series of stand-alone > IFs without the ELSEs because you somehow want more than one possible > ErrorMessage per observation, if logically that can be the case with > your data? > > Best, > MM > > On Mon, 23 Oct 2006 16:53:21 -0400, Sigurd Hermansen > <HERMANS1@WESTAT.COM> > wrote: > > >Jessica: > >The only loop that I see is the SAS Data step implicit loop; that is,

> >the SET statement as you have written it reads each row (obs) in > >dataset 'newdate' in turn and executes the statements as conditioned > >by IF ELSE statements. The do; ...end; blocks include assignments of > >messages that execute together whenever an IF or ELSE condition > >holds. > > > >I see no reason why any of the IF - ELSE statements should be in > >separate Data steps. Perhaps you should post another message to SAS-L

> >and tell us more about what you expect to happen and what is actually

> >happening when you run your program. Sig > > > >-----Original Message----- > >From: owner-sas-l@listserv.uga.edu > >[mailto:owner-sas-l@listserv.uga.edu] > >On Behalf Of phillyj > >Sent: Monday, October 23, 2006 4:32 PM > >To: sas-l@uga.edu > >Subject: do loop > > > > > >Hello everyone. Can someone please take a look at my code below and > >let me know where I am going wrong? Perhaps i am misunderstanding > >the do loop and these should all be separate data steps? Thanks! > > > >Data ERROR; > >set newdate (where=(AE_ONSET_DATE ne .)); > > > > IF year(AE_ONSET_DATE) < 2001 OR month(AE_ONSET_DATE)> 12 or > >day(AE_ONSET_DATE)>31 then > > do ; ErrorMessage='AE ONSET not within study boundries'; end; > >else IF AE_ONSET_DATE < dateregistered AND dateregistered NE . then do; > > ErrorMessage='AE ONSET is after date of randomization'; end; > >else IF AE_ONSET_DATE > AE_RESOLVED_DATE AND AE_RESOLVED_DATE NE . > >then do; > > ErrorMessage='AE ONSET is after AE RESOLVED'; end; else If > >AE_ONSET_DATE > death AND DEATH NE . then do; > > ErrorMessage='AE ONSET is after date of Death'; end; else If > >AE_ONSET_DATE < mindate AND mindate NE . then do; > > ErrorMessage='AE ONSET is before date of start therapy'; end;

> >run;


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