Help using Base SAS procedures

Change time frame in time series

Reply
Contributor
Posts: 28

Change time frame in time series

Welcome


Seeking a way that converts time series one second will do time series at 2min and 30 sec. So, the first element of a time series will start at 0:00:00 and end at 0:02:29 next start at 0:02:30 and 0:04:59 end of, the next will begin at 0:05 : 00 and end at 0:07:29 etc. Each watch is assigned observation value, which after conversion will change to 3 variables: Finally, maximum and minimum. As in the example.

I also want to do another period of time of 5 minutes, 7 minutes and 30 seconds, 10 minutes. Etc.



Thank you for your help.

Attachment
Contributor
Posts: 44

Re: Change time frame in time series

First I added datepart and timeparts variables into source data just for making calculations easier.

data have1;

  set have;

  attrib tm format=time8.;

  attrib dtp format=date9.;

  dt=input(dtc,datetime18.);

  tm=timepart(dt);

  dtp=datepart(dt);

run;

/*Then I created timegroups dataset for "sorting"  purposes */

data timegroups;

  retain lower '00:00:00't;

  attrib lower format=time8.;

  attrib time format=time8.;

  do time='00:00:00't to '23:59:59't by '00:02:30't;

  output;

  lower=time;

  end;

run;

/* Calculition of min and max in timeframe and date */

proc sql ;

  create table want1 as

  select h.dtp,

         tg.lower,

         min(h.obs) as min_obs,

         max(h.obs) as max_obs

  from   timegroups tg,

         have1 h

  where  h.tm between tg.lower and tg.time /*h.tm gt tg.lower and h.tm le tg.time */

  group  by h.dtp, tg.lower;

quit;

/' selecting last observation */

proc sql ;

  create table want2 as

  select w.*,

         h.obs as last_obs

  from   want1 w,

         have1 h

  where  h.tm between w.lower and w.lower+'00:02:30't and w.dtp = h.dtp

  group  by w.dtp, w.lower

  having h.dt= max(h.dt);

quit;

Contributor
Posts: 28

Re: Change time frame in time series

Posted in reply to AskoLötjönen

Thank you for your help

two amendment:

1.

data timegroups;

set timegroups;

time = INTNX('second',time,-1);

run;

becouse  is sas

x between 1 and 3

  x between 3 and 1

  1<=x<=3

  x>=1 and x<=3

"So, the first element of a time series will start at 0:00:00 and end at 0:02:29"

2.

  where  h.tm between w.lower and w.lower+'00:02:29't and w.dtp = h.dtp

Ask a Question
Discussion stats
  • 2 replies
  • 247 views
  • 3 likes
  • 2 in conversation