BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Kojimasan
Fluorite | Level 6

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

1 ACCEPTED SOLUTION

Accepted Solutions
Kojimasan
Fluorite | Level 6

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

6 REPLIES 6
ballardw
Super User

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;
Kojimasan
Fluorite | Level 6

 

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

 

 

ballardw
Super User

@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.

Kojimasan
Fluorite | Level 6

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);

Kojimasan
Fluorite | Level 6

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

MaksimK
Calcite | Level 5

It is a step in the right direction. Below is the example. m - integer number of month converted to "X years Y month". 

50 4 years 2 months
51 4 years 3 months
...
58 4 years 10 months
59 4 years 11 months
60 5 years 0 months

data m_to_ym;
  do m=1 to 60;
    result = catx(' ', floor(m/12), 'years', m - floor(m/12)*12, 'months');
    output;
  end;
run;

 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 6 replies
  • 5832 views
  • 1 like
  • 3 in conversation