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 (August 2008, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 28 Aug 2008 11:32:43 -0400
Reply-To:     Jonathan Goldberg <jgoldberg@BIOMEDSYS.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Jonathan Goldberg <jgoldberg@BIOMEDSYS.COM>
Subject:      Re: How to Create a flag for this logic in single datastep


It's not entirely clear what you want. However, if it's one flag record per subj, then this:

data need; retain hasdos 0; merge x y; by subj; if totdos > 0 then hasdos = 1; if last.subj then do; if hasdos = 1 & ^missing(tr) then flag = 'Y'; else flag = 'N'; hasdos = 0; output; end; run;

gives this as output:

subj flag

1 Y 2 N 3 N 4 Y

The tool needed was the last.subj variable, which is generated (along with the first.subj variable) automatically by SAS when a data set is read with a "BY", as it is in the merge. The first. and last. variables are set to 1 when the associated condition is true, to 0 otherwise.

Check out the write-up in the documentation. It's a basic data step programming tool, useful in many situations.


On Thu, 28 Aug 2008 08:07:23 -0700, Al <ali6058@GMAIL.COM> wrote:

>HI , > I have two datsets x , y .. I am supposed to merge them and >generate the flag based on this >condition if x.totdos>0 for anyday(doseno) and ne '' then Y; >else N > >I am able to get this right but in multiple datasteps .. How can it be >done in single datastep by merging > > > >Dataset X >subj doseno totdos >1 dose1 5 >1 dose2 5 >1 dose3 5 >2 dose1 7 >2 dose2 8 >2 dose3 9 >3 dose1 . >4 dose1 7 >4 dose2 8 >4 dose3 9 > >Dataset Y >subj tr >1 SD >2 >4 PD > > >Thanks in Advance

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