*读取主力合约数据; data test; set quote20120725; format date yymmdd10.; time1=input(time,time8.); format time1 time8.; *10:00:00时间格式; hour=hour(time1); *提取小时; minute=minute(time1); *提取分钟; dif_price=dif(price); *计算每笔数据的价格变量量; dif_amount=dif(amount); *计算单笔交易的成交量变化; drop time; run; *剔除集合竞价数据,9:30以前及下午开盘的集合竞价等数据; data test1; set test; if hour=9 & minute<=30 then delete; if hour=13 & minute<=5 then delete; if hour=15 & minute>15 then delete; if hour >15 then delete; run; *计算单位分钟内,价格变动引起的成交量变动量:amount_price; proc sql; create table test2 as select distinct futurecode,date,hour,minute, sum(dif_amount)/sum(dif_price) as amount_price from test1 group by hour, minute; quit; *填补缺失值,利用缺失值前面的数值填补该缺失值; Data new; set test2; time=input(catx(':',hour,minute),time5.); format time time5.; Retain xx ; if not missing(amount_price) then xx=amount_price; drop hour minute amount_price; rename xx=amount_price; run; /*计算5分钟内价格变动造成的成交量变动*/; data new3; set test2; flag=ceil(_n_/5);*建立标识变量; run; *根据标识变量进行汇总5分钟内地amount_price::m5_amount; proc sql; create table need as select * , sum(amount_price) as m5_amount from new3 group by flag; quit; *proc sort,保留一个m5_amount汇总值; proc sort data=need; by hour minute m5_amount; run; data need2; set need; by m5_amount notsorted; if last.m5_amount then output; run; data need3; set need2; time=input(catx(':',hour,minute),time5.); format time time5.; keep time m5_amount; run; *图示5分钟价格变动引起的成交量变动情况; proc sgplot data=need3; title '5分钟价格变动引起的成交量变动'; vbar time /response=m5_amount; run;
图示: