Vivian,
I liked the pur SQL solutions. For a change, here is a mixed approach:
proc sql ;
create view vall as
select y.from_date as _from_date, y.type as _type, x.*
from one x, two y
where x.id = y.id and y.from_date between x.from_date and x.to_date
;
quit ;
data four (drop = _:) ;
set vall ;
output ;
from_date = _from_date ;
type = _type ;
to_date = . ;
output ;
run ;
Kind regards
------------
Paul Dorfman
Jax, FL
------------
On Tue, 19 Jan 2010 12:32:25 -0500, V V B <vibooks@COMCAST.NET> wrote:
>Hi All,
>
>I'm trying to subset or keep data based on a date range. The data in the
>table titled data one (below) includes the date range. The data in the
>table titled two (below) represents the information I need to keep based
>on the date range in table one.
>
>If the date in table 'Data two' falls within the date range in table 'Data
>one' I need to keep both lines.
>
>I've listed examples of the data and the desired output.
>
>Your help will be most appreciated as I just don't know how to code for
>this situation.
>
>I'm using PC SAS 9.1.3.
>
>Thanks! Vivian
>
>Data one:
>input id $5. From_date date9. To_date date9. Type
>$1.;
>
>datalines;
>12345 01Jan2009 05jan2009 I;
>12345 06Mar2009 08Mar2009 I;
>45678 01jun2009 10jun2009 I;
>99899 28Jan2009 03feb2009 I;
>99811 05May2009 29May2009 I;
>44564 01apr2009 02apr2009 I;
>12312 04dec2009 19dec2009 I;
>
>Run;
>
>Data two;
>Input id $5. from_date date9. Type $1.;
>
>datalines;
>
>12345 04Jan2009 P;
>12345 06jun2009 P;
>12345 21dec2009 P;
>45678 10jun2009 P;
>45678 29may2009 P;
>99899 15jan2009 P;
>12312 06dec2009 P;
>12312 03dec2009 P;
>99811 01may2009 P;
>99811 29may2009 P;
>99811 03dec2009 P;
>44564 01mar2009 P;
>44564 15apr2009 P;
>Run;
>
>Desired output:
>
>12345 01Jan2009 05jan2009 I;
>12345 04Jan2009 P;
>45678 01jun2009 10jun2009 I;
>45678 10jun2009 P;
>99811 05May2009 29May2009 I;
>99811 29may2009 P;
>12312 04dec2009 19dec2009 I
>12312 06dec2009 P;
|
|
0
|
|
|
|
Reply
|
sashole (976)
|
1/19/2010 8:48:32 PM |
|