Date: Wed, 23 Feb 2005 04:15:44 -0800
Reply-To: Dennis Diskin <diskin@SNET.NET>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Dennis Diskin <diskin@SNET.NET>
Subject: Re: Help on comparing/observations and outputting the mean
In-Reply-To: <1109133964.659869.290810@g14g2000cwa.googlegroups.com>
Content-Type: text/plain; charset=us-ascii
Dan,
I'm afraid that your do loop makes no sense to me.
It's really a very simple problem: (untested code)
data one;
set tmp1.AA;
where dur eq . or dur ge 15;
if dur eq . then key + 1;
run;
proc means data=one;
by key;
class date;
var dur;
output out=two mean=mean;
run;
HTH,
Dennis Diskin
Dan <shao_chieh@YAHOO.COM> wrote:
Hi guys,
There are two problems I've encountered with SAS code and I hope
someone will be able to help out.
Firstly,
Objective: To have a minimum of 15 seconds duration and deleting
unwanted observations
date time dur
2/1/2002 10:00:43 .
2/1/2002 10:00:43 0
2/1/2002 10:00:53 10
2/1/2002 10:01:01 8
2/1/2002 10:02:23 82
2/1/2002 10:02:36 13
2/1/2002 10:02:37 1
2/1/2002 10:02:52 15
2/1/2002 10:03:51 59
2/1/2002 10:04:02 11
2/1/2002 10:04:12 10
2/1/2002 10:04:16 4
The new data set should look like this:
date time dur
2/1/2002 10:00:43 .
2/1/2002 10:01:01 18
2/1/2002 10:02:23 82
2/1/2002 10:02:52 29
2/1/2002 10:03:51 59
2/1/2002 10:04:12 21
The code I have tried is :
Data AA;
Set tmp1.AA nobs = nobs;
n= _n_;
p=0;
Do P = 0 to nobs;
p = p+1;
dur = dif (time);
If dur < 0 then dur = '.'; *. marks beginning of new date
If (dur < 15 and dur ne '.' and p = n) then delete;
End;
Run;
However, this code does not work because the dif function cannot be
conditional. Is there some other way around it?
Secondly, I wish to output the mean by date to another dataset. Thus
using the above data set, the sample output should look like this.
date mean
2/1/2002 41.8
2/2/2002 60
2/3/2002 50.2
..............
I really hope you guys could help me. Thanks alot.
Kind regards,
Daniel