## how to calculate the stock yeild in five minutes and the difference between the highest and the lowest price in one day

Solved
Occasional Contributor
Posts: 5

# how to calculate the stock yeild in five minutes and the difference between the highest and the lowest price in one day

hello all,

I am a freshman in SAS. Now I met two problems and hope somebody can help me.

1. how to calculate the stock yeild in five minutes;

2. how to calculate the difference between the highest and the lowest price in one day?

the data see the attachment.

Accepted Solutions
Solution
‎04-06-2014 04:56 AM
Super User
Posts: 10,778

## Re: how to calculate the stock yeild in five minutes and the difference between the highest and the lowest price in one day

You are almost get there.

```data x;
set have;
_date=input(tdate,yymmdd10.);
_time=input(substr(ttime,1,2)||':'||substr(ttime,3,2)||':'||substr(ttime,5),time.);
format _date yymmdd10. _time time.;
run;
proc sort data=x;by stkcd _date _time;run;
data stock_yield;
set x;
by stkcd _date;
yield=dif(clsprc)/lag(clsprc);
if first._date then call missing(yield);
run;

proc sql;
create table dif_high_low as
select stkcd,_date,max(clsprc)-min(clsprc) as dif
from x
group by stkcd,_date ;
quit;
```

Ksharp

All Replies
Super User
Posts: 9,599

## Re: how to calculate the stock yeild in five minutes and the difference between the highest and the lowest price in one day

Hi,

The dataset you have sent is in dBase format and hence unusable for me.  With regards to your questions:

1)

I do not understand what you mean here.  Stock yield in five minute sections?  If so create a new variable something like:

TIME     TIME_GROUP

xx:xx     FIRST_5MINS

xx:xx     FIRST_5MINS

xx:xx     SECOND_5MINS

Then do an SQL grouping by the time_group, sum(stock).

2)

proc sql;

select day,

max(price) - min(price) as diff

from     your_dataset

group by day;

quit;

Occasional Contributor
Posts: 5

## Re: how to calculate the stock yeild in five minutes and the difference between the highest and the lowest price in one day

Hi,

First of all, thank you sooooooo much for your help.

And then, please forgive my poor English. Although I have learned  English for a long time, I can't express my mind clearly.

I want to calculate the rate of return for five minutes, for example the yield between 9:30 and 9:35.

I did it like this:

data tt;

set tt;

yield=dif(clsprc)/lag(clsprc);

run;

but this programming didn't consider the factor of date.

Super User
Posts: 9,599

## Re: how to calculate the stock yeild in five minutes and the difference between the highest and the lowest price in one day

Could you provide a sample of your original data and how you want the output to look.

Occasional Contributor
Posts: 5

## Re: how to calculate the stock yeild in five minutes and the difference between the highest and the lowest price in one day

Thank U for ur patience and help~~thank u~~

Solution
‎04-06-2014 04:56 AM
Super User
Posts: 10,778

## Re: how to calculate the stock yeild in five minutes and the difference between the highest and the lowest price in one day

You are almost get there.

```data x;
set have;
_date=input(tdate,yymmdd10.);
_time=input(substr(ttime,1,2)||':'||substr(ttime,3,2)||':'||substr(ttime,5),time.);
format _date yymmdd10. _time time.;
run;
proc sort data=x;by stkcd _date _time;run;
data stock_yield;
set x;
by stkcd _date;
yield=dif(clsprc)/lag(clsprc);
if first._date then call missing(yield);
run;

proc sql;
create table dif_high_low as
select stkcd,_date,max(clsprc)-min(clsprc) as dif
from x
group by stkcd,_date ;
quit;
```

Ksharp

Occasional Contributor
Posts: 5

Super User
Posts: 10,778

## Re: how to calculate the stock yeild in five minutes and the difference between the highest and the lowest price in one day

??? You are Chinese guy ?

Occasional Contributor
Posts: 5

## Re: how to calculate the stock yeild in five minutes and the difference between the highest and the lowest price in one day

🔒 This topic is solved and locked.