```Date: Mon, 14 Apr 2003 13:52:20 -0700 Reply-To: Dale McLerran Sender: "SAS(r) Discussion" From: Dale McLerran Subject: Re: Group continuous data ? Comments: To: "Yang, Kai" In-Reply-To: <3CFAA0108952D111A5BF00805FA6FB0F05B60072@PEDSNTAS.csmc.edu> Content-Type: text/plain; charset=us-ascii Kai, Sure, that can be done easily for data sorted by A and B. The following (untested) code should work: proc sort data=mydata; by a b; run; data mydata_update; set mydata; by a b; lag_b = lag(b); * lag_b holds prior record B; if first.a then c=1; * If new value of A, C=1; else if b>(lag_b+1) then c+1; * Increment C if b>(previous b + 1); drop lag_b; run; Best wishes, Dale --- "Yang, Kai" wrote: > I want to group continuous data: > A B > 1 3 > 1 4 > 1 5 > 1 7 > 1 8 > 1 9 > 1 10 > 1 13 > 1 14 > 1 15 > 2 2 > 2 3 > 2 4 > 2 5 > 2 6 > 2 7 > 2 15 > 2 16 > 2 17 > 2 18 > 2 19 > In A=1 part, the values of B variable are 3,4,5,7,8,910,13,14,15. > Because > 3,4,5 are continuous data, so, they are in same group (C=1). Same > thing in > 7,8,910 as second group (C=2), the rest of data in third group (C=3). > In A=2 part, it should be grouped in two groups (C=1 and C=2). > The final results should be looks like: > A B C > 1 3 1 > 1 4 1 > 1 5 1 > 1 7 2 > 1 8 2 > 1 9 2 > 1 10 2 > 1 13 3 > 1 14 3 > 1 15 3 > 2 2 1 > 2 3 1 > 2 4 1 > 2 5 1 > 2 6 1 > 2 7 1 > 2 15 2 > 2 16 2 > 2 17 2 > 2 18 2 > 2 19 2 > > Is anyone know how to do that ? > Any suggestion is appreciated. > > Kai ===== --------------------------------------- Dale McLerran Fred Hutchinson Cancer Research Center mailto: dmclerra@fhcrc.org Ph: (206) 667-2926 Fax: (206) 667-5977 --------------------------------------- __________________________________________________ Do you Yahoo!? Yahoo! Tax Center - File online, calculators, forms, and more http://tax.yahoo.com ```

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