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 2007, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 6 Sep 2007 08:53:24 -0500
Reply-To:     Mary <mlhoward@avalon.net>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Mary <mlhoward@AVALON.NET>
Subject:      Re: Question: Creating ratios using a DO loop
Content-Type: text/plain; charset="iso-8859-1"

Hi, Andy,

I don't think that you need a do loop.

I would form a new column in the data that is the number of days from today's date, then this would have a number in it, 0, 1, 2, 3, etc. You would subtract the date on each record from today's date to get it; say we call it dayscount.

Then you can use SQL with a where clause:

Create table tablename select id, {calculation} as newvarname where dayscount > 2;

-Mary ----- Original Message ----- From: andymanme@GOOGLEMAIL.COM To: SAS-L@LISTSERV.UGA.EDU Sent: Thursday, September 06, 2007 7:58 AM Subject: Question: Creating ratios using a DO loop

Hi everyone,

Hope someone can help, I have a data set:

data input; format Date ddmmyy10.; input Date ddmmyy10. ID $ Var; datalines; 01/01/1980 A 6 05/01/1980 A 10 06/01/1980 A 4 07/01/1980 A 2 08/01/1980 A 10 12/01/1980 A 4 03/01/1980 B 2 09/01/1980 B 4 12/01/1980 B 6 ; run;

Using which I want to create an Average of the variable Var, the complication comes from me wishing to only use the observations per ID which are 2 days or more in the past. So for example I would wish the output to look like:

data required; format Date ddmmyy10.; input Date ddmmyy10. ID $ Var Avg; datalines; 01/01/1980 A 6 . 05/01/1980 A 10 6 06/01/1980 A 4 6 07/01/1980 A 2 8 08/01/1980 A 10 10 12/01/1980 A 4 6.4 03/01/1980 B 2 . 09/01/1980 B 4 2 12/01/1980 B 6 3 ; run;

So you can see that for ID A on 08/01/1980 we are using the observations from 01/01/1980, 05/01/1980 and 06/01/1980. We do not use the observation from 07/01/1980 as that was only 1 day prior to 08/01/1980. But when we come to calculate the average for the 12/01/1980 we are using all of the prior observations for that ID (A).

I suspect I need to use some form of DO loop to go through the data, but I am unsure as to how to code this up.

Hopefully someone can help!? Andy


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