|
You have already received some good solutions. For variety here is a single
data step approach reading the data twice.
data flagthis ;
input id x1 ;
cards ;
12 2
12 3
12 -1
13 5
13 6
13 6
14 4
14 -3
14 3
run ;
data flagged ;
do until ( last.id or x1 < 0 ) ;
set flagthis ;
by id ;
if x1 < 0 then x2 = -2 ;
else x2 = 2 ;
end ;
do until ( last.id ) ;
set flagthis ;
by id ;
output ;
end ;
run ;
Kind Regards,
__________________________
Venky Chakravarthy
E-mail: swovcc@hotmail.com
-----Original Message-----
From: Asheber Sewalem [mailto:sewalem@CDN.CA]
Sent: Thursday, October 17, 2002 2:46 PM
To: SAS-L@LISTSERV.UGA.EDU
Subject: Flag
Hi all,
A simple question!
I have two variables id and x1. I just want to flag all "Id" records -2
if any of the records x1 within id is less than 0 otherwise flag=2.
A sample data,
id x1
12 2
12 3
12 -1
13 5
13 6
13 6
14 4
14 -3
14 3
The desired output should be the following,
id x1 flag
12 2 -2
12 3 -2
12 -1 -2
13 5 2
13 6 2
13 6 2
14 4 -2
14 -3 -2
14 3 -2
Asheber
|