|
Hi,
You are getting extra flag because
the input collection_date was string
character and the sort order of the
string gives different results when
you compare > in your IF. Changing
the incoming data to a real SAS date
(by changing the informat to date11.)
then lets your IF > statement work
just fine.
data x;
retain visit;
input patient $10. visit $3.
collection_date date11.;
format collection_date date9.;
cards;
0004 00001B0116-JAN-2002
0004 00001B0313-FEB-2002
0004 00001B0509-FEB-2002
0004 00001B0802-JUL-2002
0004 00001B1027-AUG-2002
0004 00001B9917-SEP-2003
0004 00001C0113-NOV-2002
0004 00001C0706-MAY-2003
;
run;
data xx;
set x;
if visit>lag(visit) and collection_date<lag(collection_date)
then flg='NR';
run;
Hope this is helpful.
Mark Terjeson
Senior Programmer Analyst, IM&R
Russell Investment Group
Russell
Global Leaders in Multi-Manager Investing
-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of
Sridhar, Kumar
Sent: Thursday, February 16, 2006 12:11 PM
To: SAS-L@LISTSERV.UGA.EDU
Subject: Help with lag
Hi All:
Here's a question that a colleague asked me and since I was
stumped, I decided to ask you folks.
data x;
retain visit;
input patient $10. visit $3. collection_date $11.;
cards;
0004 00001B0116-JAN-2002
0004 00001B0313-FEB-2002
0004 00001B0509-FEB-2002
0004 00001B0802-JUL-2002
0004 00001B1027-AUG-2002
0004 00001B9917-SEP-2003
0004 00001C0113-NOV-2002
0004 00001C0706-MAY-2003
;
run;
If you observe, the third observation has a date of 09-FEB-2002 which is
earlier than the previous visit but the visit number is greater. I want
to put a flag on those observations (in this case the 3rd one) where the
date is earlier than the previous visit.
I tried the following but it puts a flag on all observations so any
input from you to correct the code would be really appreciated.
data x;
set x;
if visit>lag(visit) and collection_date<lag(collection_date)
then flg='NR';
run;
proc print;
run;
Kumar
|