datetime - Delete observations a certain time period apart -
so have dataset contains stock id , date_time variable amongst other things. delete observations date_time variable 30 minutes next date_time , stock same. if info set looked this:
date_time|stock_id 01apr11: 07:50:00|treasury 01apr11: 07:51:00|treasury these 2 observations deleted. far trying mark them deletion dif , lag functions. code
data 3; set 2; time_diff=dif(date_time)/60; same_stock=lag(stock); delete=.; if abs(time_diff)<=30 , same_stock=stock_id delete=1; run; after point, can drop observations delete=1. problem is, don't think code efficient , prone error, if there 3 date times next each other.
there must improve way this.
i figured out 1 way of doing think works. adds next code:
proc expand data=3 out=4 method=none; convert delete=delete_lead1 / transformout=(lead 1); run; now gives me dataset delete variable first step , lead variable (delete_lead1) give value of 1 other row need delete. checked observations , works 4 or 5 rows have more confidence in solution.
datetime sas time-series
No comments:
Post a Comment