Help using Base SAS procedures

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

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 5
Accepted Solution

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,028

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

View solution in original post


All Replies
Super User
Super User
Posts: 7,961

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
Super User
Posts: 7,961

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,028

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

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

太感谢了太感谢了~~

Super User
Posts: 10,028

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

是的,我叫曹宁,在上海社科院读研一。这几天在学SAS,老师给留了一个作业,琢磨好久不会,所以上来问问。太感谢您了。我看您的介绍里面写着“北京,中国”,所以直接中文回复了。Smiley Happy

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 8 replies
  • 269 views
  • 1 like
  • 3 in conversation