## how to get the last two digits of a year

Solved
Occasional Contributor
Posts: 10

# 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
Posts: 8,117

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

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

## 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: 10

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

Thanks for your help Tom.  Works a treat.

🔒 This topic is solved and locked.