Date: Thu, 4 Sep 2003 15:12:32 -0600 Roberto Valdivia "SAS(r) Discussion" Roberto Valdivia Help with a loop! text/plain; charset="us-ascii"

Hi!, I have a problem writting a code to make an analysis, it might be simple to solve, but unfortunately, I couldn't get it right. So, please, could anyone help me with this?. Below is the problem described, Thanks in advance, Roberto. I have a data like this: tn pc cq 1 25 245 2 50 543 3 75 645 4 100 725 5 125 876 6 150 965 7 175 1145 8 200 1178 9 225 1178 10 250 1178 First I need to estimate the difference between PCi - PCi-1 (where i=tn, i.e. when TN=2 and when TN=1 => 50-25=25), I did this using the "lag" command : DPC=PC-LAG1(PC); Same thing for the CQ variable: DCQ=CQ-LAG1(CQ); Now I have these two variables in the dataset (note that the first observation is missing for DPC and DCQ): tn pc cq dpc dcq 1 25 245 . . 2 50 543 25 298 3 75 645 25 102 4 100 725 25 80 5 125 876 25 151 6 150 965 25 89 7 175 1145 25 180 8 200 1178 25 33 9 225 1178 25 0 10 250 1178 25 0 Here is my question: I need to estimate a value like CTi=dpc*dcq/2 (i is the observation number). After this, I need to have a variable that accumulate this value each "tn", so for example: If "i" is the index for TN (observation number) for TN=1 CTAi=CTi for TN=2 CTAi=CTi + CTi-1 for TN=3 CTAi=CTi + CTi-1 +CTi-2 OR, IN GENERAL: CTAi=CTi+CTAi-1 I've tried to do this using the DO statement to build a loop but I cannot get it work. Any help will be appreciated.

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