how to get the last two digits of a year

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 9
Accepted Solution

how to get the last two digits of a year

I'm trying to pull out the last two digits of a year.  I used the following code, but i get the answer of 65.  Can anyone suggest a way I could do this?

%let yeartest=2002;

%let yeartest2=%sysfunc(putn(&yeartest,year2.);

I would like to have as the result a variable storing 02

Thanks,

Celia.


Accepted Solutions
Solution
‎10-20-2013 07:02 PM
Super User
Super User
Posts: 6,502

Re: how to get the last two digits of a year

In your example just use %SUBSTR() function.

%let yeartest=2002;

%let yeartest2=%substr(&yeartest,3) ;

If you want to find the last two digits of a DATE value then you can use the YEAR2. format.

%let yeartest2=%sysfunc(today(),year2.);

or

%let yeartest2=%sysfunc(putn("01JAN1960"d,year2.)) ;



View solution in original post


All Replies
Solution
‎10-20-2013 07:02 PM
Super User
Super User
Posts: 6,502

Re: how to get the last two digits of a year

In your example just use %SUBSTR() function.

%let yeartest=2002;

%let yeartest2=%substr(&yeartest,3) ;

If you want to find the last two digits of a DATE value then you can use the YEAR2. format.

%let yeartest2=%sysfunc(today(),year2.);

or

%let yeartest2=%sysfunc(putn("01JAN1960"d,year2.)) ;



Occasional Contributor
Posts: 9

Re: how to get the last two digits of a year

Thanks for your help Tom.  Works a treat.


☑ This topic is SOLVED.

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

Discussion stats
  • 2 replies
  • 624 views
  • 0 likes
  • 2 in conversation