It might be insightful to find out how large the data can be before the problem occurs. For example, instead of
READ ALL VAR ...
you could try
%let size = 1000;
use work.olsmat;
read next &size var {g1 g2 g3 g4 g5 g2_g1 g4_g1 g3_g1 g5_g1};
close;
etc
%let nobs = 1000;
read next &size