Select Page

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;
retain ret_colon 0;
if substr(_infile_,length(_infile_),1)=“;” then colon=1;
else colon=0;
if _infile_=“;” and ret_colon=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*/
     if upcase(_infile_)=‘RUN;’ or upcase(_infile_)=‘RUN ;’
     then goto exit;
else if ret_colon 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;
           if symexist(libnm) then libcomp=symget(libnm);
           if libref=libcomp then goto exit;
           else call symput(libnm,libref);
     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;
put _infile_;