<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Need help adapting a macro that analyzes SAS log during batch mode in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Need-help-adapting-a-macro-that-analyzes-SAS-log-during-batch/m-p/538587#M148280</link>
    <description>&lt;P&gt;This isn't the place for contract work.&amp;nbsp; There are other boards out there if you want someone to build you a tool.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Log scanning is pretty simple, open the file (infile) to read in a datastep, then read one by one and search for string using functions like index.&lt;/P&gt;
&lt;P&gt;For creating json file, in later releases there is things like:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://support.sas.com/rnd/base/Tipsheet_PROC_JSON.pdf" target="_blank"&gt;https://support.sas.com/rnd/base/Tipsheet_PROC_JSON.pdf&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Or you could just write out to a plain file using file and put statements.&lt;/P&gt;
&lt;P&gt;Both those tasks are pretty basic, and there is plenty of tutorials on reading/writing files out there.&lt;/P&gt;
&lt;P&gt;Do bear in mind that code you find on the internet may be old, not work the way you want etc.&lt;/P&gt;</description>
    <pubDate>Tue, 26 Feb 2019 08:21:03 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2019-02-26T08:21:03Z</dc:date>
    <item>
      <title>Need help adapting a macro that analyzes SAS log during batch mode</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-adapting-a-macro-that-analyzes-SAS-log-during-batch/m-p/538583#M148279</link>
      <description>&lt;P&gt;I am trying to figure out how I can adapt a macro outlined in this paper:&amp;nbsp;&lt;A href="http://support.sas.com/resources/papers/proceedings14/1762-2014.pdf" target="_blank"&gt;http://support.sas.com/resources/papers/proceedings14/1762-2014.pdf&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It analyzes the SAS log during batch mode processing. I am looking for a way to parse my log for key messages, but I don't want to send to email like in the paper, rather I want to create a JSON payload. I am not advanced enough with macro programs to decipher how to adapt this code for my needs. I've read up on ways to parse the SAS log and I really like that this one executes during batch mode. Anyone willing to give it a shot? Can you show me how to strip this macro down to just the "chase the log" part? I figure if I can get it down to just that component, I can spend more time figuring out the JSON piece. Or have another suggestion for how to parse the log in batch mode? I'm using 9.4 on Windows.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's the code from the paper (sorry for the lack of indentation):&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*This first part is placed at the beginning of your program; 
%macro chasethelog(emailid=, EndProcess=);
data _null_;
file 'chasethelog.sas';
put '%let StartTime = ' "%sysfunc(putn(%sysfunc(datetime()), datetime16.));";
put '%let User= '"%upcase(&amp;amp;SYSUSERID);";
put '%let PgmName='"%scan(%scan(&amp;amp;SYSPROCESSNAME,2,' '),1,'.');";
put '%let emailid=' "&amp;amp;emailid;";
put '%let procid='"&amp;amp;SYSJOBID;";
put '%let EndProcess=' "&amp;amp;EndProcess;";
put '%include "'chasethelog_main.sas";';
run;
systask command "chasethelog.sas";
%mend chasethelog;

%macro chasethelog_main;
%let JobStatus=1;
%let Toread=1;
 %let EndJob=0;
%let TraceWarn=0;
%let TraceError=0;
%let Iteration=0;
%do %until(&amp;amp;JobStatus=0);
%let SendMail=0;
%let Track=0;
%let WarnFlag=0;
%let ErrorFlag=0;
filenamerunlog pipe "cat &amp;amp;PgmName..log";
data a;
infilerunloglrecl=32000 length=linelength end=eof %if &amp;amp;Iteration&amp;gt;0
%then firstobs=&amp;amp;toread;;
input logline $varying700. linelength ;
if index(logline,'ERROR:') or
upcase(substr(left(logline),1,8))='WARNING:' or index(logline,'uninitialized') &amp;gt; 0
or
index(logline,'repeats of BY values') &amp;gt; 0 or
index(logline,'W.D format') &amp;gt; 0 or
index(logline,'Invalid') &amp;gt; 0 or index(logline,'Mathematical
operations could not') &amp;gt; 0 or upcase(substr(left(logline),1,10))='USER ERROR' or
upcase(substr(left(logline),1,12))='USER WARNING' or
index(logline,'outside the axis range') &amp;gt; 0 or
index(logline,'values have been converted') or
index(logline,'Missing') &amp;gt;0
then do;
callsymputx('SendMail', '1');
if index(logline,'ERROR:')=0 then call
symputx('WarnFlag',1);
output;
end;
if index(logline,'ERROR:') then do;
callsymputx('ErrorFlag',1);
if "&amp;amp;EndProcess"="Y" and &amp;amp;EndJob=0 then call
symputx('EndJob',1);
end;
callsymputx ('nrecord',_n_);
run;
%let toread=%eval(&amp;amp;nrecord+&amp;amp;toread);
%let TraceWarn=%eval(&amp;amp;TraceWarn+&amp;amp;WarnFlag);
%let TraceError=%eval(&amp;amp;TraceError+&amp;amp;ErrorFlag);
%if &amp;amp;SendMail=1 and &amp;amp;emailid^= %then %do;
filenamesendm email to="&amp;amp;emailid" Subject=%if &amp;amp;ErrorFlag=1 %then
"Error Occured in the &amp;amp;PgmName..sas Program"
 %else "Suspicious lines Occured in the &amp;amp;PgmName..sas
Program";;
data a;
set a;
output;
logline='';
output;
run;
data _null_;
set a;
filesendm;
put logline;
run;
%end;
%if &amp;amp;EndJob %then %do;
x "kill &amp;amp;procid";
%if &amp;amp;emailid^= %then filename Stats email to="&amp;amp;emailid"
Subject="%upcase(&amp;amp;PgmName.).sas Program is done with ERROR"; ;
data _null_;
file Stats;
run;
%let JobStatus=0;
%gotoEndLogCheck;
%end;
filenameprc pipe "ps u";
data b;
infileprc length=len;
input process $varying900. len;
if index(process,"&amp;amp;PgmName") and index(process,"&amp;amp;procid");
callsymputx('track',scan(process,2,' '));
run;
%if &amp;amp;track^=&amp;amp;procid %then %do;
%let JobStatus=0;
%if &amp;amp;emailid^= %then %do;
filename Status email to="&amp;amp;emailid" %if &amp;amp;TraceError&amp;gt;0 %then
Subject="%upcase(&amp;amp;PgmName.).sas Program is done with ERROR";
 %else %if &amp;amp;TraceWarn&amp;gt;0 %then
Subject="%upcase(&amp;amp;PgmName.).sas Program is done with Warning";
%else Subject="%upcase(&amp;amp;PgmName.).sas Program is with
Success";;
data _null_;
file Status;
run;
%end;
%end;
%EndLogCheck:
 %let Iteration=%eval(&amp;amp;Iteration+1);
filename _all_ clear;
%end;
%mend chasethelog_main;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 26 Feb 2019 08:02:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-adapting-a-macro-that-analyzes-SAS-log-during-batch/m-p/538583#M148279</guid>
      <dc:creator>viola</dc:creator>
      <dc:date>2019-02-26T08:02:59Z</dc:date>
    </item>
    <item>
      <title>Re: Need help adapting a macro that analyzes SAS log during batch mode</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-adapting-a-macro-that-analyzes-SAS-log-during-batch/m-p/538587#M148280</link>
      <description>&lt;P&gt;This isn't the place for contract work.&amp;nbsp; There are other boards out there if you want someone to build you a tool.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Log scanning is pretty simple, open the file (infile) to read in a datastep, then read one by one and search for string using functions like index.&lt;/P&gt;
&lt;P&gt;For creating json file, in later releases there is things like:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://support.sas.com/rnd/base/Tipsheet_PROC_JSON.pdf" target="_blank"&gt;https://support.sas.com/rnd/base/Tipsheet_PROC_JSON.pdf&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Or you could just write out to a plain file using file and put statements.&lt;/P&gt;
&lt;P&gt;Both those tasks are pretty basic, and there is plenty of tutorials on reading/writing files out there.&lt;/P&gt;
&lt;P&gt;Do bear in mind that code you find on the internet may be old, not work the way you want etc.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Feb 2019 08:21:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-adapting-a-macro-that-analyzes-SAS-log-during-batch/m-p/538587#M148280</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2019-02-26T08:21:03Z</dc:date>
    </item>
    <item>
      <title>Re: Need help adapting a macro that analyzes SAS log during batch mode</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-adapting-a-macro-that-analyzes-SAS-log-during-batch/m-p/538740#M148310</link>
      <description>&lt;P&gt;Wow, I suppose by the way my question was written, you have misinterpreted what I am asking. It occurs to me now I could have written it differently. I am not asking someone to write an entire macro for me. I'm also not asking about how to parse text or create JSON - those are the goals of my future macro, but those are pieces I am comfortable doing on my own. What I'm having trouble with is trying to tease out the piece of the code that chases the log in batch mode, so that I can replace the piece of this macro that sends the email message with something else that suits my needs. I was hoping someone could help me decipher the pieces of what the macro is doing, or maybe even point me in the direction of a different way of processing a SAS log during batch mode.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Feb 2019 18:09:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-adapting-a-macro-that-analyzes-SAS-log-during-batch/m-p/538740#M148310</guid>
      <dc:creator>viola</dc:creator>
      <dc:date>2019-02-26T18:09:34Z</dc:date>
    </item>
    <item>
      <title>Re: Need help adapting a macro that analyzes SAS log during batch mode</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-adapting-a-macro-that-analyzes-SAS-log-during-batch/m-p/538904#M148405</link>
      <description>&lt;P&gt;I would forget the macro.&amp;nbsp; When a program is run in batch (and its been a while since I did this as its all network or virtual based now), a log file, and list file is placed in the location of the main programs run location, so if you have:&lt;/P&gt;
&lt;P&gt;c:/test/myprogram.sas&lt;/P&gt;
&lt;P&gt;And batch submit this, SAS will by default create:&lt;/P&gt;
&lt;P&gt;c:/test/myprogram.log&lt;/P&gt;
&lt;P&gt;c:/test/myprogram.lst&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Therefore you can read the plain text file with the .log extension to get the log.&amp;nbsp; This is all the macro is doing, by taking the program name from the system macro variables:&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;&lt;SPAN class="token keyword"&gt;put&lt;/SPAN&gt; &lt;SPAN class="token string"&gt;'%let PgmName='&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;"%scan(%scan(&amp;amp;SYSPROCESSNAME,2,' '),1,'.');"&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/LI-CODE&gt;
&lt;P&gt;And then using this in a filename for the datastep to read from:&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;&lt;SPAN class="token string"&gt;filenamerunlog pipe "&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;cat&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;PgmName&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;log&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;";&lt;/SPAN&gt;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;You could do this simply by:&lt;/P&gt;
&lt;PRE&gt;data want;
  fname=catx('.',scan(scan("&amp;amp;sysprocessname.,2,' '),1,'.'),'.log');
  infile fname;
  length buff $2000;
  input buff $;
run;&lt;/PRE&gt;
&lt;P&gt;Then you will have the complete log read into want dataset, and can process it as you wish.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Feb 2019 09:08:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-adapting-a-macro-that-analyzes-SAS-log-during-batch/m-p/538904#M148405</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2019-02-27T09:08:40Z</dc:date>
    </item>
  </channel>
</rss>

