Hi Everyone, My problem is that for each record, I want to find the future "time" when future price> current record level. Since the data has many different object, I want to apply the above rule for each object time series. the condition is: if price2 > level and obj=object then found=1; My code below can handle it. But what I worry is that SAS will go from current record to THE END of FILE if there is no future record that meet the condition Price>current level. It will be very much inefficient since it only need to check record of the same object. I wonder if the sort step will help SAS to process more efficiently, meaning when object change, SAS will stop checking but assign grater=0 (meaning condition is not met). If this sort step doesnt help, is there any way to make it process better? Thank you, HHC data have; input object time price level; datalines; 1 1 5 9 1 2 2 3 1 3 8 5 1 4 10 25 1 5 12 63 2 1 15 29 2 2 12 3 2 3 18 15 2 4 10 15 2 5 18 6 3 1 15 29 3 2 22 32 3 3 8 52 3 4 11 50 3 100 1200 6 ;run; proc sort; by object time;run; data want (keep=object time price level greater); set have nobs=totalobs; i+1; found=0; do j=i+1 to totalobs until (found=1) ; set have(keep=object time price rename=(object =obj time=greater price=price2)) point=j; if price2 > level and obj=object then found=1; end; if found=0 then greater=0; run;
... View more