Hi:
If date is a character string (such as you show), then SUBSTR will work. But if date is a numeric value, as shown in the program below, then the results will not be correct. Since the OP said his date value was numeric, SUBSTR on a numeric variable would force a conversion of the internally stored number from numeric to character in order for the SUBSTR to work (since it will ONLY work on CHARACTER variables or text strings).
See the log and program below, where the internally stored date for 06/01/1989 is the number 10744 (Jun 1, 1989 is 10744 days from Jan 1, 1960). So when 10744 was converted to a text string it was converted with the BEST12. format, which resulted in the string xxxxxxx10744 (where every x is a space). So the SUBSTR would get x107 -- where the x is a space -- so the substr results in newvar2 having the string ' 107' with a leading space. (The PUT statement does not show leading spaces -- nor do most SAS procedures.)
cynthia
[pre]
1289 data one;
1290 chardate='06/01/1989';
1291 NewVariable=substr(chardate,7,4);
1292 put chardate= newvariable=;
1293
1294 numdate = '01jun1989'd;
1295 newvar2 = substr(numdate,7,4);
1296 put "formatted val for " numdate= mmddyy10. " Internal val for " numdate= newvar2=;
1297 run;
NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column).
1295:18
chardate=06/01/1989 NewVariable=1989
formatted val for numdate=06/01/1989 Internal val for numdate=10744 newvar2=107
NOTE: The data set WORK.ONE has 1 observations and 4 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
[/pre]