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 (January 2001, week 5)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Tue, 30 Jan 2001 15:36:34 -0800
Reply-To:     Dale McLerran <dmclerra@MY-DEJA.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Dale McLerran <dmclerra@MY-DEJA.COM>
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 <Mmccoy@NATHANASSOC.COM> >From: Michael McCoy <Mmccoy@NATHANASSOC.COM> >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