[prev in list] [next in list] [prev in thread] [next in thread] 

List:       sas-l
Subject:    Re: Log output to SAS code
From:       Bob Burnham <Robert.A.Burnham () DARTMOUTH ! EDU>
Date:       1999-10-29 17:42:09
[Download RAW message or body]

Bruce Bradbury (remove XX) <B.BradburyXX@unsw.edu.au> wrote in message
news:7valuo$d2j$1@mirv.unsw.edu.au...
> Are there any macros available which take log file output (eg from the
> MPRINT statement) and produce clean sas code?
>
>

I might be misunderstanding the question -- but if you are ever stuck in a
situation where you only have a LOG file and want to recover the original
SAS code that created it, something like this might help.  It relies on the
fact that the SAS log puts numbers in the first column followed by the code.
As a result, this won't really work if you have in-line data using a CARDS
statement.

/*
   Quick program to recover a SAS program from a log file.

   Basic rules:

   [1] Skip the first line (always a title)
   [2] Only keep lines with a number in the first column
   [3] If you find a page break, delete the next line
*/

%let nums=0123456789;
%let spaces=12;

data _null_;
  length inLine $200;
  retain delNext 0;
  infile "old_program.log" truncover lrecl=200 firstobs=2;
  file "recovered_prog.sas" lrecl=200;
  input inLine $200.;
  fc = substr(inLine, 1, 1);
  if ((delNext = 0) and (indexc(fc, "&nums") > 0)) then do;
    inLine = substr(inLine, &spaces);
    put inLine;
  end;
  if indexc(inLine, '0C'x) then delNext = 1;
  else delNext = 0;
  run;

Vice versa, if you are on a UNIX system (or you happen to have some
UNIX-type utilities installed), a much shorter sed script should get you
pretty close:

# only keep lines beginning with a number
/^[0-9]/!d
# get rid of the number and extra spaces
s/^[0-9]* \{1,12\}//

Best regards,

Bob

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic