```Date: Tue, 30 Jan 2001 15:36:34 -0800 Reply-To: Dale McLerran Sender: "SAS(r) Discussion" From: Dale McLerran Subject: Re: BY statement while using the DIF function Comments: To: mmccoy@nathanassoc.com Content-Type: text/plain Michael, It is not clear whether there is such a regular structure through all of the data as there is for the first two customers who each have just 3 records. My guess is that there is not such a regular structure. My reading of your request is that you want to form all pairwise differences within a particular customer. I think the most efficient way to perform this will be to use temporary arrays to hold all customer data up to the time that the last record for a given customer is encountered and then generate the differences using array processing. Here is how this might look: data diffs; set raw; by customer; array raw {100} _temporary_; if first.customer then nrec=0; nrec+1; raw{nrec}=price; if last.customer then do; do i=1 to nrec-1; do j=i+1 to nrec; diff = raw{i} - raw{j}; rec1 = i; rec2 = j; output; end; end; end; run; The dimension of the array RAW should be at least the size of the greatest customer frequency count which you expect. What happens when you load the data into a temporary array is that you are actually loading the data into RAM memory. When the last customer record is encountered, you simply look up all the filled spaces in the RAM memory, so this is a computationally feasible and flexible solution. >Date: Mon, 29 Jan 2001 11:53:31 -0500 >Reply-To: Michael McCoy >From: Michael McCoy >Subject: BY statement while using the DIF function >To: SAS-L@LISTSERV.UGA.EDU > >Is it possible to use the DIF function on grouped data? > >For example, in the data below, is it possible to return the difference in >price of customer1 between its three observations and the difference in >price of customer2 over its three observations, but not compare observation >3 to 4 due to the fact that they are in different groups? > > >Obs Customer Price >1 Customer1 10 >2 Customer1 20 >3 Customer1 30 >4 Customer2 40 >5 Customer2 50 >6 Customer2 60 > > > >Thanks for the help. > > >Michael McCoy >Research Associate >Nathan Associates, Inc. >703 516-7755 > > > > ><< msg2.html >> Dale --------------------------------------- Dale McLerran Fred Hutchinson Cancer Research Center mailto: dmclerra@fhcrc.org Ph: (206) 667-2926 Fax: (206) 667-5977 --------------------------------------- ------------------------------------------------------------ --== Sent via Deja.com ==-- http://www.deja.com/ ```

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