Date: Wed, 25 Apr 2007 09:41:12 -0700
Reply-To: jofo <joey.foley@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: jofo <joey.foley@GMAIL.COM>
Organization: http://groups.google.com
Subject: Output observations to two datasets
Content-Type: text/plain; charset="iso-8859-1"
Hello again,
Sorry for the second posting. It didn't appear on the web so I am
reposting.
Also, this should give more clarity.
This is my working code below.
I am processing these datasets multiple times. I would like to see if
I can process this once.
I grab the first.id in the first pass. Then grab the observations
that are on or after the cutoff date.
Then merge the two passes back together keeping the first.id from each
dataset.
Is there an easier way to do this perhaps, only passing over the
dataset test2 only once?
Can you output the first.id and then test against the cutoff date or
does the PDV clear once output?
Thanks and thank you to those who responded by email.
Hopefully this will clarify questions I received.
data test1;
input id $ cutoff yymmdd8. ;
format cutoff yymmddn8.;
datalines;
01 20000304
02 20000101
03 20000405
04 20000401
;
run;
data test2;
input id $ date_1 yymmdd8. ;
format date_1 yymmddn8.;
datalines;
01 20000102
01 20000202
01 20000306
02 20000101
02 20000202
02 20000203
02 20000303
03 20000405
03 20000505
03 20000520
03 20000607
04 20000102
04 20000203
04 20000317
;
run;
proc sort data=work.test2;
by id date_1;
run;
*Create set of first observations;
data first;
set test2;
by id;
if first.id then output;
run;
*Create set of observations after cutoff date;
data second;
merge test1(in=in1) test2(in=in2);
by id;
if cutoff =< date_1 ;
run;
*Merge datasets back keeping the first observations from each;
data third;
merge first(in=in1) test1(in=inT1) second(in=in2
rename=(date_1=date_2) drop=cutoff);
by id;
if first.id;
run;