BookmarkSubscribeRSS Feed
iloveinsurance
Calcite | Level 5

I have a dataset like this:

Account NumberIndividual NumberVehicle NumberKilometres Driven
1245112815
12452129536
1245311000
12451277521
12452296643
1245322662
12451386077
12452384798
12453367814
11221188179
11222193435
11221384491
11222376614

 

 

I want to take the minimum kilometres driven by account number and then rank the individuals.

Which I have done here:

proc sort data=lowestkm; by accountnumber kmdriven; run;

data lowestkm;
set file;
lowestcountaccount +1;
by accountnumber kmdriven;
if first.accountnumber then lowestcountaccount = 1;
run;

Which gives me this:

Account NumberIndividual NumberVehicle NumberKilometres Drivenlowestcountaccount
12451128153
124521295364
12453110001
124512775216
124522966439
12453226622
124513860778
124523847987
124533678145
112211881793
112221934354
112213844912
112223766141

 

 

The problem is, I can only have the individual flag occur once by each account. 

I was hoping to create a flag like this:

The lowest ranking is 1, so individual number 3 is assigned "Y" for the first vehicle under the first account.

The second lowest number after that is 77521, so individual number 1 is assigned "Y" for the second vehicle.

Lastly what is left is individual number 2 which is assigned "Y" on the third vehicle.

I can have up to 5 individual numbers and 5 vehicle numbers. 

Account NumberIndividual NumberVehicle NumberKilometres DrivenPrincipal KM Driven
1245112815 
12452129536 
1245311000Y
12451277521Y
12452296643 
1245322662 
12451386077 
12452384798Y
12453367814 
11221188179Y
11222193435 
11221384491 
11222376614Y

 

 

 

2 REPLIES 2
PeterClemmensen
Tourmaline | Level 20

I'm sorry, I don't follow this logic. Can you be more specific?

ChrisNZ
Tourmaline | Level 20

If I understand correctly, this does what you need.

Untested as you did not provide data in usable form (data step or SQL create/insert step).

data WANT;
   set HAVE;
   by ACCOUNTNUMBER KM;
   length DRIVERS VEHICLES  $80 ;
   if index(DRIVERS,DRIVER)=0 & index(VEHICLES,VEHICLE)=0 then do;
     PRINCIPAL = 'Y';
     DRIVERS   = catx('|',DRIVERS ,DRIVER );
     VEHICLES  = catx('|',VEHICLES,VEHICLE);
   end;
 run;

 

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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
  • 567 views
  • 2 likes
  • 3 in conversation