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 (September 2003, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Fri, 5 Sep 2003 10:21:04 +0200
Reply-To:   "Groeneveld, Jim" <jim.groeneveld@VITATRON.COM>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   "Groeneveld, Jim" <jim.groeneveld@VITATRON.COM>
Subject:   Re: Help with a loop!
Comments:   To: Roberto Valdivia <valdivia@MONTANA.EDU>
Content-Type:   text/plain; charset="iso-8859-1"

Hi Roberto,

No other replies to your Q yet, so it is my turn [;-)

For TN (or _N_) = 1 you already indicate DPC and DCQ to be missing. So in that case CTi would be missing as well. That means that CTAi would be missing for TN=1 too and while all subsequent CTAi's would be accumulated from CTAi for TN=1, they all would be missing. I assume that you want all non-missing sums, so I have developed the following code:

DATA LoopTest; INPUT TN PC CQ; DPC=PC-LAG1(PC); DCQ=CQ-LAG1(CQ); CTi=dpc*dcq/2; RETAIN CTAi; IF (_N_ /* or TN */ EQ 1) THEN CTAi = CTi; * thus missing for TN=1; ELSE CTAi = SUM ( CTi, CTAi ); * Even without the IF/ELSE the last assignment could apply always, also for TN=1; CARDS; 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 ; RUN;

PROC PRINT DATA = LoopTest; RUN;

Regards - Jim.

Y. (Jim) Groeneveld MSc Biostatistician Vitatron B.V. Meander 1051 6825 MJ Arnhem The Netherlands +31/0 26 376 7365; fax 7305 Jim.Groeneveld@Vitatron.com www.vitatron.com

-----Original Message----- From: Roberto Valdivia [mailto:valdivia@MONTANA.EDU] Sent: Thursday, September 04, 2003 23:13 To: SAS-L@LISTSERV.UGA.EDU Subject: Help with a loop! Importance: High

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