LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous (more recent) messageNext (less recent) messagePrevious (more recent) in topicNext (less recent) in topicPrevious (more recent) by same authorNext (less recent) by same authorPrevious page (December 2008, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Mon, 1 Dec 2008 14:14:13 -0500
Reply-To:     Paul Dorfman <sashole@BELLSOUTH.NET>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Paul Dorfman <sashole@BELLSOUTH.NET>
Subject:      Re: A Range Checking Problem - Very Urgent ( Please help me)
Comments: To: Tom Smith <need_sas_help@YAHOO.COM>

Tom,

To the offers you have already got, this DATA step requires no prior sorting of either input file:

data help (keep = subject travelday) ; if _n_ = 1 then do ; dcl hash h () ; h.definekey ('subject' ) ; h.definedata ('lo', 'hi') ; h.definedone () ; do until (z) ; set help2 end = z ; ff = ^^ h.find() ; lo = sum (lo, + ff * 1e99) min travelday ; hi = sum (hi, - ff * 1e99) max travelday ; h.replace() ; end ; end ; set help1 (rename = (visitday = travelday)) ; if h.find() | ^ (lo <= travelday <= hi) ; run ;

The intent is to attach LO and HI dates from HELP2 to each of its keys in hash H while the latter is being loaded, then dump HI and LO into PDV for each key coming from HELP1. A bit of finagling with FF is needed to ensure that LO and HI are determined properly for each subject (every time it is not yet in the hash table, the initial comparison constants for LO and HI are set to values guaranteed to always exceed the former and be less than the latter, respectively).

The construct ff = ^^h.find() does a few things at once:

1) if a key is found, writes LO and HI from hash table H to PDV 2) if the key is found, returns 0 (evaluating false), else returns a non- zero, non-missing value (evaluating true) 3) normalizes true to 1 and false to 0, thus providing the intended value for the ensuing multiplication 4) prevents SAS from barfing an error when a key is not found, which it would if it encountered a naked h.find().

Kind regards ------------ Paul Dorfman Jax, FL ------------

On Sun, 30 Nov 2008 22:26:27 -0500, Tom Smith <need_sas_help@YAHOO.COM> wrote:

>I have two following data sets (named: Help1, help2) : > >Dataset named Help1 (Variables:subject,Visitday) should be as below: > >subject Visitday >------- --------- >101 23JAN2001 >101 29DEC2002 >101 12JAN2003 >101 15JUN2008 >102 17MAR2002 >102 28JAN2003 >102 25FEB2004 >102 29DEC2005 >102 01FEB1986 >209 12JAN2002 >209 11DEC2003 >209 15JAN2003 >209 14JAN2004 >210 22FEB2002 > >Dataset named help2 (Variables:subject,travelday) should be as below: > >subject travelday >------- -------- >101 25JAN2001 >101 30DEC2002 >101 12JAN2003 >102 16MAR2002 >102 28JAN2003 >102 25FEB2003 >102 31DEC2005 >209 12JAN2001 >209 11DEC1992 >209 16JAN2003 >209 20FEB2004 > > > > >Now I have to check if the visitday of dataset help1 is in the range of >the >travelday of help2 (for subject 101 it should be in between 25JAN2001 and >12JAN2003; for subject 102 it should be in between 16MAR2002 and >31DEC2005; >for subject 209 it should be in between 12JAN2001 and 20FEB2004) > >and output those are not in range should be as below ( result): > >subject travelday >------ --------- >101 23JAN2001 >101 15JUN2008 >102 01FEB1986 >210 22FEB2002


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