BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
audreyliu201
Fluorite | Level 6

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;
1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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;

View solution in original post

2 REPLIES 2
Astounding
PROC Star

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;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 698 views
  • 3 likes
  • 2 in conversation