BookmarkSubscribeRSS Feed
makset
Obsidian | Level 7

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.

2 REPLIES 2
AskoLötjönen
Quartz | Level 8

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;

makset
Obsidian | Level 7

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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 932 views
  • 3 likes
  • 2 in conversation