Convert number to years/months

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 7
Accepted Solution

Convert number to years/months

Hi all,

 

So I have a variable called 'Vintage', it's in the format of YYMMD7.

Vintage has values such as '2011-02' or 2009-03'.

 

Then I have a variable called OriginalTerm in the format of 11.

It's basically numbers in months format, so if the value of 60 is displayed for the observation, I want a new variable called 'ConvertedOriginalTerm' to be converting the number 60 into years/months, so 60 should be displayed 5 years - 0 months.

 

I'm looking at IDs from january 2015. 

 

If account 45A has originalterm 60, vintage of '2009-02', then convertedoriginalterm should display 5 years - months. 

And another variable shows the MonthsRemaining on the loan, so from 2011-01 to january 2015, the account still has 12 months left, and i want this new varaible 'MonthsRemainign' to display 12.

 

I hope i was clear


Accepted Solutions
Solution
‎10-17-2017 11:40 AM
Occasional Contributor
Posts: 7

Re: Convert number to years/months

Posted in reply to Kojimasan

Apparently, there was another variable which had exactly what I was looking for in another dataset and just joined it with my present one. Thanks guys

View solution in original post


All Replies
Super User
Posts: 13,286

Re: Convert number to years/months

Posted in reply to Kojimasan

Do you want your convertedoriginalterm  to be character?

 

From your problem description I have no Idea why you include: I'm looking at IDs from january 2015. 

Or any other date information if the sole bit of result is to take a numeric value, divide by 12 to get months and then take the remainder.

 

Does this show the correct results for 1 to 60 values of your original item:

 

data junk;
  do x=1 to 60;
  result = catx(' ',round(x/12,1),'years',mod(x,12),'months');
  output;
  end;
run;
Occasional Contributor
Posts: 7

Re: Convert number to years/months

 

Good question, I want the convertedoriginalterm to be a number. Perhaps split it into, convertedoriginalyears, and convertedoriginalmonths?

 

The code you gave , has these results:

Obs x result 1 2 3 4 5 6 7 8 9 10 11 12

10 years 1 months
20 years 2 months
30 years 3 months
40 years 4 months
50 years 5 months
61 years 6 months
71 years 7 months
81 years 8 months
91 years 9 months
101 years 10 months
111 years 11 months
121 years 0 months

 

 

Super User
Posts: 13,286

Re: Convert number to years/months

Posted in reply to Kojimasan

Kojimasan wrote:

 

Good question, I want the convertedoriginalterm to be a number. Perhaps split it into, convertedoriginalyears, and convertedoriginalmonths?

 

The code you gave , has these results:

Obs x result 1 2 3 4 5 6 7 8 9 10 11 12

1 0 years 1 months
2 0 years 2 months
3 0 years 3 months
4 0 years 4 months
5 0 years 5 months
6 1 years 6 months
7 1 years 7 months
8 1 years 8 months
9 1 years 9 months
10 1 years 10 months
11 1 years 11 months
12 1 years 0 months

 

 


Since your request was:

If account 45A has originalterm 60, vintage of '2009-02', then convertedoriginalterm should display 5 years - months. 

 

That's what I aimed for. Show your expected results explicitly or you get unexpected results.

Occasional Contributor
Posts: 7

Re: Convert number to years/months

[ Edited ]

I tried this, this is a step in the right direction but now I want to add the length of this original termyears and orignaltermmonths to the vintage date.

convertedoriginalyears = floor(originalterm/12);
convertedoriginalmonths = originalterm-(12*convertedoriginalyears);

Solution
‎10-17-2017 11:40 AM
Occasional Contributor
Posts: 7

Re: Convert number to years/months

Posted in reply to Kojimasan

Apparently, there was another variable which had exactly what I was looking for in another dataset and just joined it with my present one. Thanks guys

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 301 views
  • 1 like
  • 2 in conversation