BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
smackerz1988
Pyrite | Level 9

I have a specification for the variable ADURN

 

smackerz1988_0-1661423065979.png

 

Here is the example of the data from SUDUR and the desired output for ADURN

 

SUDURADURN
P9Y9
P10Y10
P46Y46
P1Y6M1.6
P3Y3
P15Y15
P3Y3
P2Y2
P25Y25
P2Y2
P4Y4
P7Y6M7.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)

 

SUDURENDDURDY
P9Y28399680032879
P10Y315532800365210
P46Y14516064001680146
P1Y6M470880005451.49
P3Y9460800010953
P15Y473299200547815
P8Y25246080029228
P23Y725760000840023
P50Y15778368001826250
P20Y631152000730520
P50Y15778368001826250
P31Y9782208001132231
P12Y378691200438312
P15Y473299200547815
P20Y631152000730520
P10Y315532800365210
P5Y15776640018265
P2Y630720007302
P5Y15776640018265
P40Y12623040001461040
P30Y9466848001095730
P1Y315360003651
P1Y315360003651
P12Y378691200438312
P26Y820454400949626
P10Y315532800365210
P28Y8836128001022728
P39Y12306816001424439
P10Y315532800365210
P5Y15776640018265
P4Y12623040014614
P17Y536457600620917
P10Y315532800365210
P10Y315532800365210
P20Y631152000730520
P15Y473299200547815
P10Y315532800365210
P10Y315532800365210
P22Y694224000803522
P23Y725760000840023
P18Y567993600657418
P3Y9460800010953
P10Y315532800365210
P5Y15776640018265
P8Y25246080029228
P3Y9460800010953
P2Y630720007302
P25Y788918400913125
P2Y630720007302
P4Y12623040014614
P7Y6M23639040027367.49

 

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

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.

View solution in original post

1 REPLY 1
FreelanceReinh
Jade | Level 19

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.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 365 views
  • 1 like
  • 2 in conversation