I have a specification for the variable ADURN
Here is the example of the data from SUDUR and the desired output for ADURN
SUDUR | ADURN |
P9Y | 9 |
P10Y | 10 |
P46Y | 46 |
P1Y6M | 1.6 |
P3Y | 3 |
P15Y | 15 |
P3Y | 3 |
P2Y | 2 |
P25Y | 25 |
P2Y | 2 |
P4Y | 4 |
P7Y6M | 7.6 |
I was just going to compress SUDUR with the kd modifier but if you look at the examples highlighted in red this would cause an error as they would be populated 16 and 76 instead of 1.6 and 7.6. Is there an informat that converts to IS0 8601 or a practical way to account for months in SUDUR?
EDIT: Okay I have found this code
* ADURN *;
if ~missing(sudur) then do;
CALL IS8601_CONVERT('DU', 'DU', SUDUR, endDUR);
D=enddur/86400;
Y=D/365.25;
Y=round(Y, 0.01);
end;
However the calculations for SUDUR which contains months are slightly off (please see highlighted examples below)
SUDUR | ENDDUR | D | Y |
P9Y | 283996800 | 3287 | 9 |
P10Y | 315532800 | 3652 | 10 |
P46Y | 1451606400 | 16801 | 46 |
P1Y6M | 47088000 | 545 | 1.49 |
P3Y | 94608000 | 1095 | 3 |
P15Y | 473299200 | 5478 | 15 |
P8Y | 252460800 | 2922 | 8 |
P23Y | 725760000 | 8400 | 23 |
P50Y | 1577836800 | 18262 | 50 |
P20Y | 631152000 | 7305 | 20 |
P50Y | 1577836800 | 18262 | 50 |
P31Y | 978220800 | 11322 | 31 |
P12Y | 378691200 | 4383 | 12 |
P15Y | 473299200 | 5478 | 15 |
P20Y | 631152000 | 7305 | 20 |
P10Y | 315532800 | 3652 | 10 |
P5Y | 157766400 | 1826 | 5 |
P2Y | 63072000 | 730 | 2 |
P5Y | 157766400 | 1826 | 5 |
P40Y | 1262304000 | 14610 | 40 |
P30Y | 946684800 | 10957 | 30 |
P1Y | 31536000 | 365 | 1 |
P1Y | 31536000 | 365 | 1 |
P12Y | 378691200 | 4383 | 12 |
P26Y | 820454400 | 9496 | 26 |
P10Y | 315532800 | 3652 | 10 |
P28Y | 883612800 | 10227 | 28 |
P39Y | 1230681600 | 14244 | 39 |
P10Y | 315532800 | 3652 | 10 |
P5Y | 157766400 | 1826 | 5 |
P4Y | 126230400 | 1461 | 4 |
P17Y | 536457600 | 6209 | 17 |
P10Y | 315532800 | 3652 | 10 |
P10Y | 315532800 | 3652 | 10 |
P20Y | 631152000 | 7305 | 20 |
P15Y | 473299200 | 5478 | 15 |
P10Y | 315532800 | 3652 | 10 |
P10Y | 315532800 | 3652 | 10 |
P22Y | 694224000 | 8035 | 22 |
P23Y | 725760000 | 8400 | 23 |
P18Y | 567993600 | 6574 | 18 |
P3Y | 94608000 | 1095 | 3 |
P10Y | 315532800 | 3652 | 10 |
P5Y | 157766400 | 1826 | 5 |
P8Y | 252460800 | 2922 | 8 |
P3Y | 94608000 | 1095 | 3 |
P2Y | 63072000 | 730 | 2 |
P25Y | 788918400 | 9131 | 25 |
P2Y | 63072000 | 730 | 2 |
P4Y | 126230400 | 1461 | 4 |
P7Y6M | 236390400 | 2736 | 7.49 |
Hello @smackerz1988,
If only "Y" and possibly "M" (but not "D") occur in your SUDUR values, it should be correct to round Y to 1/12 years (rather than 0.01).
Y=round(D/365.25, 1/12);
Note that "1 year, 6 months" are 1.5 years, not 1.6.
BTW, thanks for reminding me of the CALL IS8601_CONVERT routine. I had used it in 2012, but then almost forgot about it.
Hello @smackerz1988,
If only "Y" and possibly "M" (but not "D") occur in your SUDUR values, it should be correct to round Y to 1/12 years (rather than 0.01).
Y=round(D/365.25, 1/12);
Note that "1 year, 6 months" are 1.5 years, not 1.6.
BTW, thanks for reminding me of the CALL IS8601_CONVERT routine. I had used it in 2012, but then almost forgot about it.
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: