LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (October 2000, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Wed, 18 Oct 2000 15:15:51 -0600
Reply-To:   Kenneth Moody <KennethMoody@FIRSTHEALTH.COM>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   Kenneth Moody <KennethMoody@FIRSTHEALTH.COM>
Subject:   Re: Data manipulation help
Comments:   To: zulsdad@IWON.COM
Content-Type:   text/plain; charset=us-ascii

Yusuf,

Following is a tested bit of code that might work for you. You might want to add logic if anything needs to be done for a new value of road_inv or a gap in mp values. This code assumes that the deg_curv value for a combined curve is the value which was in the first section; if it's not the same in all sections, you might want to pick the last or the average.

HTH.

* Read the test data; data roaddata; input road_inv begmp endmp deg_curv acc n_br_a; *road_inv begmp endmp deg_curv acc n_br_a; cards; 002 133.58 133.75 0.00 0 0.51 002 133.75 133.77 3.50 0 0.11 002 133.77 133.90 3.50 1 0.37 002 133.90 134.01 0.00 1 0.25 002 134.01 134.11 6.50 0 0.38 002 134.11 134.15 0.00 1 0.09 002 134.15 134.19 0.00 1 0.16 002 134.19 134.25 0.00 0 0.13 002 134.25 134.35 4.00 0 0.32 002 134.35 134.44 0.00 0 0.21 002 134.44 134.55 0.00 1 0.25 002 134.55 134.83 4.00 0 0.74 002 134.83 134.87 0.00 0 0.09 002 134.87 134.96 6.00 1 0.33 002 134.96 135.05 0.00 0 0.21 002 135.05 135.12 0.00 0 0.14 002 135.12 135.14 0.00 0 0.04 002 135.14 135.20 8.99 0 0.31 002 135.20 135.24 0.00 1 0.09 002 135.24 135.37 10.00 0 0.50 002 135.37 135.44 10.00 1 0.39 002 135.44 135.45 0.00 0 0.03 002 135.45 135.56 10.00 0 0.45 002 135.56 135.58 0.00 0 0.04 ;;;; proc print data=roaddata; run; data tangent curve; retain is_curve begmp_c endmp_c deg_curc acc_c n_br_a_c 0; drop is_curve begmp_c endmp_c deg_curc acc_c n_br_a_c; set roaddata end=lastobs; by road_inv begmp; if deg_curv = 0 then do; /* current segment is a tangent */ output tangent; if is_curve = 1 then do; /* prior segment was a curve */ begmp = begmp_c; /* restore saved values */ endmp = endmp_c; deg_curv = deg_curc; acc = acc_c; n_br_a= n_br_a_c; output curve; end; is_curve = 0; end; else do; /* current segment is a curve */ if is_curve = 0 then do; /* prior segment not a curve */ begmp_c = begmp; /* save the info for the first segment */ endmp_c = endmp; deg_curc= deg_curv; acc_c = acc; n_br_a_c= n_br_a; is_curve = 1; end; else do; /* prior segment was also a curve */ endmp_c = endmp; /* update curve values */ acc_c + acc; n_br_a_c + n_br_a; end; if lastobs then do; /* if this is the last obs it must be output */ begmp = begmp_c; /* restore saved values */ endmp = endmp_c; deg_curv = deg_curc; acc = acc_c; n_br_a= n_br_a_c; output curve; end; end; run; proc print data=tangent; title 'tangent'; proc print data=curve; title 'curve'; run;

Ken Moody First Health, Metrics Department Voice: 916-374-3924 EMail: KennethMoody@firsthealth.com

>>> "Yusuf Mohamedshah" <zulsdad@IWON.COM> 10/18 12:25 PM >>> Dear SAS-L'ers

I have following data set which one of 98. It is a continous roadway section identified by road_inv, begmp and endmp. And each of the section is either a tangent (deg_curv = 0) or a curve (deg_curv > 0) plus there are two additional variables: acc which is observed accidents for three year period and n_br_a which is predicted accidents for same three year period.

road_inv begmp endmp deg_curv acc n_br_a

002 133.58 133.75 0.00 0 0.51 002 133.75 133.77 3.50 0 0.11 002 133.77 133.90 3.50 1 0.37 002 133.90 134.01 0.00 1 0.25 002 134.01 134.11 6.50 0 0.38 002 134.11 134.15 0.00 1 0.09 002 134.15 134.19 0.00 1 0.16 002 134.19 134.25 0.00 0 0.13 002 134.25 134.35 4.00 0 0.32 002 134.35 134.44 0.00 0 0.21 002 134.44 134.55 0.00 1 0.25 002 134.55 134.83 4.00 0 0.74 002 134.83 134.87 0.00 0 0.09 002 134.87 134.96 6.00 1 0.33 002 134.96 135.05 0.00 0 0.21 002 135.05 135.12 0.00 0 0.14 002 135.12 135.14 0.00 0 0.04 002 135.14 135.20 8.99 0 0.31 002 135.20 135.24 0.00 1 0.09 002 135.24 135.37 10.00 0 0.50 002 135.37 135.44 10.00 1 0.39 002 135.44 135.45 0.00 0 0.03 002 135.45 135.56 10.00 0 0.45 002 135.56 135.58 0.00 0 0.04

I want to separate above roadway sections into two data sets: tangents and curves. That is the easy part. But for curves, I want to combine the adjacent curves which are split and sum the acc and n_br_a for those curves. So the second and third would be combine to give following observation:

002 133.75 133.90 3.5 0 0.48

Similarly the fifth and fourth observation from the bottom would be combined to give:

002 135.24 135.44 10.0 1 0.89

The final output for curves should have 8 observations since there are 8 distinct curves in the above set. I have tried several ways to get the output (using SQL and Proc Summary) but I could not figure out how to combine the two adjacent observations to form a single curve and than sum the values of acc and n_br_a. As I said I above there are 98 similar datasets (or sites) which I have to process. Any help would be greatly appreciated.

Thanks

Yusuf M. Mohamedshah Program Manager, Safety Research Highway Safety Information System (HSIS) Lendis Corporation Federal Highway Administration 6300 Georgetown Pike McLean, VA 22101 PH: 202 493 3464 FX: 202 493 3374

........................................................ iWon.com http://www.iwon.com why wouldn't you? ........................................................


Back to: Top of message | Previous page | Main SAS-L page