Given the following SAS Code which is applied to a SAS Date Set containing several explanatory variables and specifically a CHAR Variable: MAIN_DOB which contains the date of birth of the main applicant in the following format: 1978-06-28 We need to calculate the age of the applicant in years at the time of contract initiation. Contract_Start_Date_DT is a SAS Date in the format 25/06/2014 The following SAS Code works but surely there is a more elegant / efficient solution to this simple problem DATA LIBXYZ.DEVELOPMENT_SAMPLE_03 ; SET LIBXYZ.DEVELOPMENT_SAMPLE_02 ; SearchDate_DT = DATEPART(SearchDate) ; QuoteDate_DT = DATEPART(QuoteDate) ; Contract_StartDate_DT = DATEPART(Contract_StartDate) ; Vehicle_RegistrationDate_DT = DATEPART(Vehicle_RegistrationDate) ; Termination_Date_DT = DATEPART(Termination_Date) ; Termination_CarDisposalDate_DT = DATEPART(Termination_CarDisposalDate) ; DateOfBirth_Char = INPUT( COMPRESS( MAIN_DOB,"-" ) , $8. ) ; DateOfBirth_Year = INPUT( SUBSTR(DateOfBirth_Char , 1 , 4 ) , 4. ) ; DateOfBirth_Month = INPUT( SUBSTR(DateOfBirth_Char , 5 , 2 ) , 2. ) ; IF DateOfBirth_Month < 10 THEN DateOfBirth_Month1 = CAT('0' , DateOfBirth_Month ) ; ELSE DateOfBirth_Month1 = DateOfBirth_Month ; DateOfBirth_Day = INPUT( SUBSTR(DateOfBirth_Char , 7 , 2 ) , 2. ) ; IF DateOfBirth_Day < 10 THEN DateOfBirth_Day1 = CAT('0' , DateOfBirth_Day ) ; ELSE DateOfBirth_Day1 = DateOfBirth_Day ; DateOfBirth = INPUT(CATX( '/' , DateOfBirth_Day1 , DateOfBirth_Month1 , DateOfBirth_Year ) , ddmmyy10. ) ; FORMAT SearchDate_DT QuoteDate_DT Contract_StartDate_DT Vehicle_RegistrationDate_DT Termination_Date_DT Termination_CarDisposalDate_DT ddmmyy10. ; FORMAT DateOfBirth ddmmyy10. ; CONTRACT_AGE = ( YEAR(Contract_StartDate_DT) - DateOfBirth_Year ) ; FORMAT CONTRACT_AGE 4. ; DROP SearchDate QuoteDate Contract_StartDate Vehicle_RegistrationDate Termination_Date Termination_CarDisposalDate DateOfBirth_Char DateOfBirth_Year DateOfBirth_Month DateOfBirth_Day DateOfBirth_Day1 DateOfBirth_Month1 ; RUN; Thanks for kind assistance
... View more