BookmarkSubscribeRSS Feed
SaggiK
Calcite | Level 5

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

7 REPLIES 7
RichardinOz
Quartz | Level 8

try in a data step (or SQL equivalent)

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

Richard

Message was edited by: Richard Carson - added missing parameter

Ksharp
Super User

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

SaggiK
Calcite | Level 5

Hi All,

Thank you for your solutions.

Regards,

Saggi

udo_sas
SAS Employee

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

SaggiK
Calcite | Level 5

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

udo_sas
SAS Employee

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

SaggiK
Calcite | Level 5

Udo,

Thank you - this is very helpful.

Saggi

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 7 replies
  • 973 views
  • 0 likes
  • 4 in conversation