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
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
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;
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 |
@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.
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);
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
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;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.