Hi, Do you know how to write this in a simpler way?
data distanceclass;
set combine;
retain Dist_class 0;
If 0<miles<=0.5 then dist_class=0.5;
If 0.5<miles<=1 then dist_class=1.0;
If 1.0<miles<=1.5 then dist_class=1.5;
If 1.5<miles<=2.0 then dist_class=2.0;
If 2.0<miles<=2.5 then dist_class=2.5;
If 2.5<miles<=3.0 then dist_class=3.0;
If 3.0<miles<=3.5 then dist_class=3.5;
If 3.5<miles<=4.0 then dist_class=4.0;
If 4.0<miles<=4.5 then dist_class=4.5;
If 4.5<miles<=5.0 then dist_class=5.0;
If 5.0<miles<=5.5 then dist_class=5.5;
If 5.5<miles<=6.0 then dist_class=6.0;
If 6.0<miles<=6.5 then dist_class=6.5;
If 6.5<miles<=7.0 then dist_class=7.0;
If 7.0<miles<=7.5 then dist_class=7.5;
If 7.5<miles<=8.0 then dist_class=8.0;
If 8.0<miles<=8.5 then dist_class=8.5;
If 8.5<miles<=9.0 then dist_class=9.0;
If 9.0<miles<=9.5 then dist_class=9.5;
If 9.5<miles<=10.0 then dist_class=10.0;
If 10.0<miles<=10.5 then dist_class=10.5;
If 10.5<miles<=11.0 then dist_class=11.0;
If 11.0<miles<=11.5 then dist_class=11.5;
If 11.5<miles<=12.0 then dist_class=12.0;
If 12.0<miles<=12.5 then dist_class=12.5;
If 12.5<miles<=13.0 then dist_class=13.0;
If 13.0<miles<=13.5 then dist_class=13.5;
If 13.5<miles<=14.0 then dist_class=14.0;
If 14.0<miles<=14.5 then dist_class=14.5;
If 14.5<miles<=15.0 then dist_class=15.0;
If 15.0<miles<=15.5 then dist_class=15.5;
If 15.5<miles<=16.0 then dist_class=16.0;
If 16.0<miles<=16.5 then dist_class=16.5;
If 16.5<miles<=17.0 then dist_class=17.0;
If 17.0<miles<=17.5 then dist_class=17.5;
If 17.5<miles<=18.0 then dist_class=18.0;
If 18.0<miles<=18.5 then dist_class=18.5;
If 18.5<miles<=19.0 then dist_class=19.0;
If 19.0<miles<=19.5 then dist_class=19.5;
If 19.5<miles then dist_class=20.0;
run;
For most categories, you can get away with:
dist_class = ceil(2 * miles) / 2;
For the higher values, you also need to add:
if dist_class > 20 then dist_class = 20;
For most categories, you can get away with:
dist_class = ceil(2 * miles) / 2;
For the higher values, you also need to add:
if dist_class > 20 then dist_class = 20;
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 how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.