SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
StickyRoll
Fluorite | Level 6

Hello guys. I have a difficult task that needs help with.

So I am working on some contracts data with Policy as the key.

1 Police_ID can have multiple endorsement (AKA Version).

For example:
POLICE_ID   END_ID POLICE_EFFECTIVE_DATE  POLICE_EXPIRY_DATEEND_SER_EFFECTIVE_DATE END_SER_END_DATE

A                      0             01Jan2024                                31Dec2024                  01Jan2024                                   05Mar2024

A                      1              01Jan2024                                31Dec2024                 06Mar2024                                  31Dec2024

 

As we can see, a single POLICE_ID (Policy number) can have 2 END_ID (endorsement or we call it version) with different endorsement date (END_EFFDATE and END_EXPDATE).

 

Here is the task that i have been cracking my head. The data is not in the desired form at the moment and i am supposed to transform the data into that format as above.

This is what I got: 
Below sample is all for a single POLICE_ID. In reality, I have more than 100,000 of POLICE_ID.
Scenario A (Extended Period)

Originally    
END_IDEND_SER_EFFECTIVE_DATEEND_SER_END_DATEPOLICE_EFFECTIVE_DATEPOLICE_EXPIRY_DATE
01/1/202431/12/20241/1/202431/12/2024
11/2/202431/12/20241/1/202431/12/2024
21/1/202531/1/20251/1/202431/12/2024


It should be transformed into:

END_IDEND_SER_EFFECTIVE_DATEEND_SER_END_DATEPOLICE_EFFECTIVE_DATEPOLICE_EXPIRY_DATE
01/1/202431/1/20241/2/202431/1/2025
11/2/202431/12/20241/2/202431/1/2025
21/1/202531/1/2025  

In the end result, for END_ID = 0, the value of "END_SER_END_DATE" is populated from "END_SER_EFFECTIVE_DATE"-1 in END_ID = 1. The logic for this is because there shouldn't be any date of "END_SER_XXX_DATE" overlap with the next line of "END_ID".
Moreover, since this is an extended scenario, the POLICE_EFFECTIVE_DATE and POLICE_EXPIRY_DATE is now changed. For POLICE_EFFECTIVE_DATE, it will be based on the new POLICE_EXPIRY_DATE - 1 year.

Data step to produce Scenario A sample data (original):
data insurance_data;
infile datalines dlm=',' dsd;
format END_SER_EFFECTIVE_DATE END_SER_END_DATE POLICE_EFFECTIVE_DATE POLICE_EXPIRY_DATE ddmmyy10.;
input POLICE_ID $ END_ID END_SER_EFFECTIVE_DATE :ddmmyy10. END_SER_END_DATE :ddmmyy10.
POLICE_EFFECTIVE_DATE :ddmmyy10. POLICE_EXPIRY_DATE :ddmmyy10.;
datalines;
AA,0,01/01/2024,31/12/2024,01/01/2024,31/12/2024
AA,1,01/02/2024,31/12/2024,01/01/2024,31/12/2024
AA,2,01/01/2025,31/01/2025,01/01/2024,31/12/2024
;
run;

 

 

Scenario B (Shifted Period)

Originally    
END_IDEND_SER_EFFECTIVE_DATEEND_SER_END_DATEPOLICE_EFFECTIVE_DATEPOLICE_EXPIRY_DATE
01/1/202431/12/20241/1/202431/12/2024
115/2/202431/12/20241/1/202431/12/2024
21/2/202431/1/20251/1/202431/12/2024

 

It should be transformed into:

END_IDEND_SER_EFFECTIVE_DATEEND_SER_END_DATEPOLICE_EFFECTIVE_DATEPOLICE_EXPIRY_DATE
01/2/202414/2/20241/2/202431/1/2025
115/2/202431/1/20251/2/202431/1/2025

For this scenario, END_SER_EFFECTIVE_DATE of the final row of END_ID will become the new END_SER_EFFECTIVE_DATE for the first nearest date to 1/2/2024 and new POLICE_EFFECTIVE_DATE for the same POLICE ID of all END_ID. 

Like wise, the END_SER_END_DATE in the final END_ID will become the new END_SER_END_DATE for the END_ID before the final END_ID (which in this example is END_ID = 1) and new POLICE_EXPIRY_DATE for the same POLICE ID of all END_ID. 

Lastly, remove the final END_ID.


Data step to produce Scenario B sample data (original):
data insurance_data;
infile datalines dlm=',' dsd;
format END_SER_EFFECTIVE_DATE END_SER_END_DATE POLICE_EFFECTIVE_DATE POLICE_EXPIRY_DATE ddmmyy10.;
input POLICE_ID $ END_ID END_SER_EFFECTIVE_DATE :ddmmyy10. END_SER_END_DATE :ddmmyy10.
POLICE_EFFECTIVE_DATE :ddmmyy10. POLICE_EXPIRY_DATE :ddmmyy10.;
datalines;
AA,0,01/01/2024,31/12/2024,01/01/2024,31/12/2024
AA,1,15/02/2024,31/12/2024,01/01/2024,31/12/2024
AA,2,01/02/2024,31/01/2025,01/01/2024,31/12/2024
;
run;

I hope both scenarios are clear. Feel free to ask anything as I understand the logic may not be simple and that more illustrations can be provided if you need more info.

 

 

1 REPLY 1
ChrisNZ
Tourmaline | Level 20

It looks like people have been overwhelmed by the wall of text, and have no time to spend deciphering your complex explanations. 

Try simplifying what you want to achieve to increase uptake.

sas-innovate-white.png

🚨 Early Bird Rate Extended!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.

 

Lock in the best rate now before the price increases on April 1.

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
  • 1 reply
  • 358 views
  • 1 like
  • 2 in conversation