Removing extraneous code in RMFI resolved code

If you have been using this tip for generating resolved code in your RMFI programs, you have probably noticed a lot of extra code that - whilst necessary to generate initial results - is not required to recreate those results.  This is due to the fact that a lot of code is used to dynamically generate further code.

In any case, here is a program I use to make the resolved code more manageable:


%let loc=C:tempMyResolvedCode.txt;
proc sql;
create table x as select _ from dictionary.macros
where scope=‘GLOBAL’ and substr(name,1,4)=‘LIB;
data _null; set x; call execute(‘%symdel ’||name||’;’); run;
%put executed on %sysfunc(datetime(),datetime19.);
data null;
infile ”&loc” lrecl=32767 missover;
file ”&loc.2” lrecl=32767;
input;
retain retcolon 0;
if substr(_infile,length(infile),1)=”;” then colon=1;
else colon=0;
if infile=”;” and retcolon=1 then goto exit;
else if subpad(_infile,1,11)=“filename T” then goto exit;
else if upcase(_infile)=:‘DATA NULL then
     do until(infile=‘run;’);/_ code will exit below anyway/
     input;
     if upcase(infile)=‘RUN;’ or upcase(infile)=‘RUN ;’
     then goto exit;
end;
else if retcolon and colon then do;
     if upcase(_infile)=‘QUIT;’ or upcase(infile)=‘QUIT ;’
     then goto exit;
     else if *infile=:‘call symput’ then goto exit;
     else if infile=:“label ” and count(infile,’“’)=2
          and count(infile,’=’)=1 then goto exit;
     else if infile=:‘put ”ERROR: Object with’ then goto exit;
     else if upcase(infile)=: ‘LIBNAME’ then do;
          /* remove consecutive libnames pointing to same place */
           if find(upcase(infile),’ CLEAR;’) then goto exit;
           else if find(upcase(infile),’ TMP ’) then goto exit;
           libnm=cats(‘LIB,scan(_infile,2));
           if symexist(libnm) then libcomp=symget(libnm);
           libref=scan(infile,2,’“’);
           if libref=libcomp then goto exit;
           else call symput(libnm,libref);
     end;
     else if upcase(infile)=:‘SELECT ’
           and ( find(upcase(infile),’ INTO :’)
           orfind(upcase(infile),’ INTO:’) )
           then goto exit;
     else if upcase(infile)=:‘OPTIONS’ then goto exit;
     else if upcase(infile)=:‘FILENAME ’ then goto exit;
end;
put infile;
infile=infile;
output;
exit:
ret_colon=colon;
run;