BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Beonly
Calcite | Level 5

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

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

8 REPLIES 8
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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;

Beonly
Calcite | Level 5

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.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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

Ksharp
Super User

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

Beonly
Calcite | Level 5

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

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
  • 8 replies
  • 976 views
  • 1 like
  • 3 in conversation