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.
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
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;
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.
Could you provide a sample of your original data and how you want the output to look.
Thank U for ur patience and help~~thank u~~
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
太感谢了太感谢了~~
??? You are Chinese guy ?
是的,我叫曹宁,在上海社科院读研一。这几天在学SAS,老师给留了一个作业,琢磨好久不会,所以上来问问。太感谢您了。我看您的介绍里面写着“北京,中国”,所以直接中文回复了。
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.