LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (March 2006, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Fri, 24 Mar 2006 15:20:36 -0600
Reply-To:   Jiann-Shiun Huang <Jiann-Shiun.Huang@AMERUS.COM>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   Jiann-Shiun Huang <Jiann-Shiun.Huang@AMERUS.COM>
Subject:   Re: Using PROC SQL to create a rolling count by unit
Comments:   To: mkjohnst@GMAIL.COM
Content-Type:   text/plain; charset=US-ASCII

Michael:

Here is an implementation.

data test; input id xb time; cards; 1 0 1 1 0 1 1 0 2 1 0 3 1 0 5 2 0 1 2 0 2 2 0 2 ; run;

data test1; set test; by id; if first.id then count=0; count+1; run;

proc sql; create table temp as select A.id, A.xb, A.time, A.count, case when A.time le B.time then 1 else 0 end as Ind from test1 A join test1 B on A.id eq B.id; create table test2 as select id, xb, time, sum(Ind) as IndCount from temp group by id, xb, time, count; quit;

proc print data=test2; run;

***** Output ***** The SAS System 10:32 Friday, March 24, 2006 603

Ind Obs id xb time Count

1 1 0 1 5 2 1 0 1 5 3 1 0 2 3 4 1 0 3 2 5 1 0 5 1 6 2 0 1 3 7 2 0 2 2 8 2 0 2 2

J S Huang 1-515-557-3987 fax 1-515-557-2422

>>> Michael Johnston <mkjohnst@GMAIL.COM> 3/24/2006 2:24:06 PM >>> Hi all,

I have data that look something like this:

data test; input id xb time; cards; 1 0 1 1 0 1 1 0 2 1 0 3 1 0 5 2 0 1 2 0 2 2 0 2 ; run;

I would like to create a new variable, E, that is the number of records for each ID with values of TIME greater than or equal to the value of TIME for the current observation. The data are already sorted by ID and TIME. That is, I would like my output data to look something like this:

data test2; input id xb time e; cards; 1 0 1 5 1 0 1 5 1 0 2 3 1 0 3 2 1 0 5 1 2 0 1 3 2 0 2 2 2 0 2 2 ; run;

Is it possible to accomplish this within PROC SQL?

Best regards,

Mike


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