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 1999, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Fri, 22 Oct 1999 14:04:00 -0400
Reply-To:     Quentin McMullen <Quentin_McMullen@ABTASSOC.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Quentin McMullen <Quentin_McMullen@ABTASSOC.COM>
Subject:      Re: scanning 1 variable against others
Content-Type: multipart/mixed;

There are probably better solutions, but I recently came up with the following to handle a similar situation. Basically I transpose the file with the start and stop dates for each range, then merge on the event dates and run over arrays to check if the event is within *any* range for each id. Worked for me cuz the max number of ranges for an ID was seven. I don't know SQL, but I think you can merge in SQL with multiple by values and have it produce one record for each possible combination of by values (can't do this with merge, AFAIK). No doubt SQL will handle something like this much better, and you'll probably get better non-SQL solutions as well.

HTH, --Q.

data range; input id start stop; cards; 1 2 5 1 6 7 1 8 10 2 1 3 2 5 9 2 10 14 ; run;

data event; input id date; cards; 1 1 1 3 1 6 2 2 2 4 2 5 2 7 ; run;

data a; set range; by id; if first.id then period=0; *counter for number of time periods; period+1; run;

proc print data=a;run;

proc transpose data=a out=b; var start stop; by id period; run;

proc print data=b;run;

data c; set b; _name_=compress(_name_||period); run;

proc print data=c;run;

proc transpose data=c out=d; var col1; by id; run;

proc print data=d;run;

data both; merge event (keep=id date) d (keep=id start1-start3 stop1-stop3) ; by id; array start{3}; array stop{3}; do i=1 to dim(start); if start{i}<=date<=stop{i} then in=1; end; if in=. then in=0; run;

proc print data=both;run;

______________________________ Reply Separator _________________________________ Subject: scanning 1 variable against others Author: Mahboobeh Safaeian <msafaeia@JHSPH.EDU> at internet Date: 10/22/1999 12:53 PM

can you please suggest how to take the datex variable, scan it against the date-6m and date, if it falls within the range to get a 1 value, if none of the datex fall within the date-6m & date range to return a 0 value?

thanks mahboobeh


<html> <font size=2>Dear list members:<br> <br> i have a data set as follows:<br> <br> <b>id <x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; date-6m&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; date<br> </b>10019&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 04/20/94&nbsp;&nbsp;&nbsp; 10/19/94&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br> 10019&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 10/11/94&nbsp;&nbsp;&nbsp; 04/11/95&nbsp;&nbsp;&nbsp;&nbsp; <br> 10019&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 05/12/95&nbsp;&nbsp;&nbsp; 11/10/95&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br> 10019&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 10/12/95&nbsp;&nbsp;&nbsp; 04/11/96&nbsp;&nbsp;&nbsp; <br> 10019&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 03/26/96&nbsp;&nbsp;&nbsp; 09/24/96<br> <br> i have another data set with the following<br> <br> <b>id<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>&nbsp;&nbsp;&nbsp;&nbsp; datex<br> </font></b><font face="Arial, Helvetica" size=2>10019&nbsp;&nbsp;&nbsp; 09/20/94&nbsp;&nbsp;&nbsp; <br> 10019&nbsp;&nbsp;&nbsp; 10/13/94&nbsp;&nbsp;&nbsp; <br> 10019&nbsp;&nbsp;&nbsp; 11/03/94&nbsp;&nbsp;&nbsp; <br> 10019&nbsp;&nbsp;&nbsp; 11/22/94&nbsp;&nbsp;&nbsp; <br> 10019&nbsp;&nbsp;&nbsp; 12/09/94&nbsp;&nbsp;&nbsp; <br> 10019&nbsp;&nbsp;&nbsp; 12/15/94&nbsp;&nbsp;&nbsp; <br> 10019&nbsp;&nbsp;&nbsp; 03/24/95&nbsp;&nbsp;&nbsp; <br> 10019&nbsp;&nbsp;&nbsp; 03/31/95&nbsp;&nbsp;&nbsp; <br> 10019&nbsp;&nbsp;&nbsp; 04/07/95&nbsp;&nbsp;&nbsp; <br> 10019&nbsp;&nbsp;&nbsp; 04/13/95&nbsp;&nbsp;&nbsp; <br> 10019&nbsp;&nbsp;&nbsp; 04/21/95&nbsp;&nbsp;&nbsp; <br> 10019&nbsp;&nbsp;&nbsp; 04/27/95&nbsp;&nbsp;&nbsp; <br> 10019&nbsp;&nbsp;&nbsp; 05/04/95&nbsp;&nbsp;&nbsp; <br> 10019&nbsp;&nbsp;&nbsp; 05/08/95&nbsp;&nbsp;&nbsp; <br> 10019&nbsp;&nbsp;&nbsp; 07/06/95&nbsp;&nbsp;&nbsp; <br> 10019&nbsp;&nbsp;&nbsp; 11/13/95&nbsp;&nbsp;&nbsp; <br> 10019&nbsp;&nbsp;&nbsp; 11/20/95&nbsp;&nbsp;&nbsp; <br> 10019&nbsp;&nbsp;&nbsp; 11/20/95&nbsp;&nbsp;&nbsp; <br> <br> can you please suggest how to take the datex variable, scan it against the date-6m and date, if it falls within the range to get a 1 value, if none of the datex fall within the date-6m &amp; date range to return a 0 value?<br> <br> thanks<br> mahboobeh </font></html>


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