10-18-2012 02:42 PM
I have a macro reading the Yr in and the Yr is a four digit. How can I select the last 2 digit and put it in another variable like Yr2 that I want to use in the same macro. I tried SUBSTR but it doesnt work.
/*Yr = 1993 , 1994 , 1995*/
yr2 = SUBSTR(yr,3,2);
10-18-2012 03:03 PM
SUBSTR() is a function that can operate on data, but in your code YR is macro variable and not a variable in a SAS dataset.
Plus to reference the value of your macro variable you need to prefix the name with an &. To assign the value to another macro variable you need to use %LET statement.
You can use the %SUBSTR() function to select part of the string that is the value of macro variable.
%let yr2=%substr(&yr,3,2) ;
%put yr2=&yr2 ;