Time Series Transformations

Reply
New Contributor
Posts: 4

Time Series Transformations

Hi all,


I'm using stock (intraday) transaction data recorded at irregular points in time (e.g., 9:45 ; 9:48 ; 9:49).
I want to convert the data to fix time interval so I can perform some statistical time series analysis, for example the stock price every 2 minutes.

I tried using "proc expand", but didn't find a way to do it. Is this kind of conversion possible using "proc expand" or am I looking in the wrong direction?

I saw some examples with proc timeseries - maybe this is a better way of doing it?

Thanks,
Saggi

Super Contributor
Posts: 644

Re: Time Series Transformations

try in a data step (or SQL equivalent)

timestat = intnx('MINUTE2', timestamp, 0, 'END') ;

Richard

Message was edited by: Richard Carson - added missing parameter

Super User
Posts: 10,041

Re: Time Series Transformations

Yeah. proc expand can achieve that.

data a;
input time : time8. v;
format time time8.;
cards;
09:45 21
09:48 45
09:49 34
09:54 32
10:02 56
;
run;
proc sort data=a; by time;run;
data aa;
 merge a a(firstobs=2 rename=(time=_time));
 output;
 do t=time+60 to coalesce(_time-60,0) by 60;
  time=t;v=.;output;
 end;
drop t _time;
run;
proc expand data=aa out=bb method=spline;
      id time;
   run;

Xia Keshan

New Contributor
Posts: 4

Re: Time Series Transformations

Hi All,

Thank you for your solutions.

Regards,

Saggi

SAS Employee
Posts: 416

Re: Time Series Transformations

Hello Saggi -

As you mentioned earlier you may want to consider PROC TIMESERIES which analyzes time-stamped transactional data with respect to time and accumulates the data into a time series format as yet another option.

An example can be found here: http://support.sas.com/documentation/cdl/en/etsug/66840/HTML/default/viewer.htm#etsug_timeseries_exa...

Thanks,

Udo

New Contributor
Posts: 4

Re: Time Series Transformations

Udo,

Thanks you for the reference.

I saw that the example code uses a time interval of a month ("id timestamp interval=month") whereas I want to use a time interval of a second (or millisecond).

I read the proc's syntax but I didn't find any details of the possible frequencies I can use in this option. can you direct me to the relevant documentation?

Thanks again,

Saggi

SAS Employee
Posts: 416

Re: Time Series Transformations

Saggi -

A list of all supported intervals of the TIMESERIES procedure can be found here: http://support.sas.com/documentation/cdl/en/etsug/66840/HTML/default/viewer.htm#etsug_intervals_sect...

Thanks,

Udo

New Contributor
Posts: 4

Re: Time Series Transformations

Udo,

Thank you - this is very helpful.

Saggi

Ask a Question
Discussion stats
  • 7 replies
  • 419 views
  • 0 likes
  • 4 in conversation