BookmarkSubscribeRSS Feed
R2211BAL
Calcite | Level 5

New to SAS.. Working on SAS Studio, Looking for SAS code for the following scenario

 

I have a data with the following variables

city A     city B    Miles    Price

a1             a2      1059     150

a1             a3      1089     150

a1             a4      1509     200

a1             a5       600       150

a1             a6      1989     200 

 

And I am looking to create an output like 

 

City A     Miles-Lowerlimit         Miles-Upperlimit                   Price

   a1           600                              1089                              150

   a1            509                             1989                              200

 

 

Thank You!!

2 REPLIES 2
PeterClemmensen
Tourmaline | Level 20

Do like this

 

data have;
input city_A $ city_B $ Miles Price;
datalines;
a1 a2 1059 150
a1 a3 1089 150
a1 a4 1509 200
a1 a5 600 150
a1 a6 1989 200
;

proc sql;
   create table want as
   select city_A
         ,min(Miles) as Miles_Lowerlimit
         ,max(Miles) as Miles_Upperlimit
         ,price
   from have
   group by city_A, price;
quit;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1283 views
  • 0 likes
  • 3 in conversation