<?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: Parse SAS Log file in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Parse-SAS-Log-file/m-p/357087#M83799</link>
    <description>&lt;P&gt;Concur with &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/88384"&gt;@Shmuel&lt;/a&gt;. use the index() and scan() functions; index() to detect the presence of a certain string, and scan() to extract a certain "word" from the string.&lt;/P&gt;
&lt;P&gt;The data step would look like that:&lt;/P&gt;
&lt;P&gt;- declare the infile with truncover and a end=done option&lt;/P&gt;
&lt;P&gt;- retain variables for datasetname, number of records and real time&lt;/P&gt;
&lt;P&gt;- set length for datasetname to $32&lt;/P&gt;
&lt;P&gt;- when you encounter a index(text,"NOTE: The data set") = 1, do:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; - if datasetname is already set (indicating that you've been collecting data already), output&lt;/P&gt;
&lt;P&gt;&amp;nbsp; - set datasetname with scan(text,5," ") and extract nrecs with nrecs = input(scan(text,7," ",best.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp; - set realtime to missing&lt;/P&gt;
&lt;P&gt;when you encounter "real time" in text, extract realtime like nrecs (experiment until you get the correct "word" number)&lt;/P&gt;
&lt;P&gt;when if done is true and datasetname &amp;gt; " ", output (to write the last occurence)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The check for the NOTEs from SQL look similar to that for a data step, just the words and positions are different&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 09 May 2017 08:19:32 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2017-05-09T08:19:32Z</dc:date>
    <item>
      <title>Parse SAS Log file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Parse-SAS-Log-file/m-p/357076#M83794</link>
      <description>&lt;P&gt;I have a sas log . For example :&lt;/P&gt;&lt;P&gt;NOTE: The data set WORK.A has 1 observations and 1 variables.&lt;BR /&gt;NOTE: DATA statement used (Total process time):&lt;BR /&gt;real time 0.01 seconds&lt;BR /&gt;user cpu time 0.01 seconds&lt;BR /&gt;system cpu time 0.01 seconds&lt;BR /&gt;memory 764.06k&lt;BR /&gt;OS Memory 18596.00k&lt;BR /&gt;Timestamp 05/08/2017 11:26:34 PM&lt;BR /&gt;Step Count 6 Switch Count 30&lt;BR /&gt;Page Faults 0&lt;BR /&gt;Page Reclaims 351&lt;BR /&gt;Page Swaps 0&lt;BR /&gt;Voluntary Context Switches 73&lt;BR /&gt;Involuntary Context Switches 1&lt;BR /&gt;Block Input Operations 0&lt;BR /&gt;Block Output Operations 312&lt;/P&gt;&lt;P&gt;28&lt;BR /&gt;29 data B;&lt;BR /&gt;30 set A;&lt;BR /&gt;31 x=3;&lt;BR /&gt;32 run;&lt;/P&gt;&lt;P&gt;NOTE: There were 1 observations read from the data set WORK.A.&lt;BR /&gt;NOTE: The data set WORK.B has 1 observations and 2 variables.&lt;BR /&gt;NOTE: DATA statement used (Total process time):&lt;BR /&gt;real time 0.00 seconds&lt;BR /&gt;user cpu time 0.01 seconds&lt;BR /&gt;2 The SAS System 23:11 Monday, May 8, 2017&lt;/P&gt;&lt;P&gt;system cpu time 0.00 seconds&lt;BR /&gt;memory 1032.62k&lt;BR /&gt;OS Memory 18856.00k&lt;BR /&gt;Timestamp 05/08/2017 11:26:34 PM&lt;BR /&gt;Step Count 7 Switch Count 40&lt;BR /&gt;Page Faults 0&lt;BR /&gt;Page Reclaims 297&lt;BR /&gt;Page Swaps 0&lt;BR /&gt;Voluntary Context Switches 111&lt;BR /&gt;Involuntary Context Switches 0&lt;BR /&gt;Block Input Operations 0&lt;BR /&gt;Block Output Operations 328&lt;/P&gt;&lt;P&gt;33&lt;BR /&gt;34 proc sql;&lt;BR /&gt;35 create table XYZ as select * from B;&lt;BR /&gt;NOTE: Table WORK.XYZ created, with 1 rows and 2 columns.&lt;/P&gt;&lt;P&gt;36 quit;&lt;BR /&gt;NOTE: PROCEDURE SQL used (Total process time):&lt;BR /&gt;real time 0.00 seconds&lt;BR /&gt;user cpu time 0.00 seconds&lt;BR /&gt;system cpu time 0.00 seconds&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;After Each data step or Proc step there is statistics of real time and CPU time. I want to parse and create dataset which will have dataset name and real time . Like&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Table &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Time &amp;nbsp; &amp;nbsp; records&amp;nbsp;&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;Work.A &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0.01 &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;Work.B &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0.00 &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;Work.XYZ &amp;nbsp; &amp;nbsp;0.00 &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying like this but not able to capture Table /dataset name .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;filename in "log_path";&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data x;&lt;BR /&gt;infile inn missover truncover;&lt;BR /&gt;input text $1000. ;&lt;BR /&gt;b=strip(text);&lt;BR /&gt;x=compress(text);&lt;BR /&gt;c=substr(x,1,8);&lt;BR /&gt;zz=compress(x,'realtime');&lt;BR /&gt;if text eq '' then delete;&lt;BR /&gt;if c='realtime';&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;could someone please help ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;</description>
      <pubDate>Tue, 09 May 2017 07:21:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Parse-SAS-Log-file/m-p/357076#M83794</guid>
      <dc:creator>Saurabh13</dc:creator>
      <dc:date>2017-05-09T07:21:06Z</dc:date>
    </item>
    <item>
      <title>Re: Parse SAS Log file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Parse-SAS-Log-file/m-p/357078#M83795</link>
      <description>&lt;P&gt;Please repost your log snippet using the {i} icon, so that the original formatting is preserved.&lt;/P&gt;</description>
      <pubDate>Tue, 09 May 2017 07:36:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Parse-SAS-Log-file/m-p/357078#M83795</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-05-09T07:36:52Z</dc:date>
    </item>
    <item>
      <title>Re: Parse SAS Log file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Parse-SAS-Log-file/m-p/357081#M83796</link>
      <description>&lt;PRE&gt;25         data A;
26          s=2;
27         run;

NOTE: The data set WORK.A has 1 observations and 1 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      user cpu time       0.01 seconds
      system cpu time     0.00 seconds
      memory              765.00k
      OS Memory           18340.00k
      Timestamp           05/09/2017 12:41:45 AM
      Step Count                        2  Switch Count  29
      Page Faults                       0
      Page Reclaims                     425
      Page Swaps                        0
      Voluntary Context Switches        67
      Involuntary Context Switches      0
      Block Input Operations            0
      Block Output Operations           304
      

28         
29         data B;
30          set A;
31          x=3;
32         run;

NOTE: There were 1 observations read from the data set WORK.A.
NOTE: The data set WORK.B has 1 observations and 2 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      user cpu time       0.00 seconds
2                                                          The SAS System                                 00:41 Tuesday, May 9, 2017

      system cpu time     0.00 seconds
      memory              1030.53k
      OS Memory           18600.00k
      Timestamp           05/09/2017 12:41:45 AM
      Step Count                        3  Switch Count  39
      Page Faults                       0
      Page Reclaims                     314
      Page Swaps                        0
      Voluntary Context Switches        92
      Involuntary Context Switches      0
      Block Input Operations            0
      Block Output Operations           320
      

33         
34         proc sql;
35          create table XYZ as select * from B;
NOTE: Table WORK.XYZ created, with 1 rows and 2 columns.

36         quit;
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.00 seconds
      user cpu time       0.01 seconds
      system cpu time     0.00 seconds
      memory              5419.12k
      OS Memory           23464.00k
      Timestamp           05/09/2017 12:41:45 AM
      Step Count                        4  Switch Count  29
      Page Faults                       0
      Page Reclaims                     149
      Page Swaps                        0
      Voluntary Context Switches        67
      Involuntary Context Switches      0
      Block Input Operations            0
      Block Output Operations           304&lt;/PRE&gt;</description>
      <pubDate>Tue, 09 May 2017 07:46:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Parse-SAS-Log-file/m-p/357081#M83796</guid>
      <dc:creator>Saurabh13</dc:creator>
      <dc:date>2017-05-09T07:46:54Z</dc:date>
    </item>
    <item>
      <title>Re: Parse SAS Log file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Parse-SAS-Log-file/m-p/357082#M83797</link>
      <description>&lt;P&gt;Each log line has its own format.&lt;/P&gt;
&lt;P&gt;Use functions &lt;STRONG&gt;index&lt;/STRONG&gt;&amp;nbsp;or &lt;STRONG&gt;find &lt;/STRONG&gt;to check for wanted keywords like DATA, OUT=, observations, real time, etc.&lt;/P&gt;
&lt;P&gt;When found use function &lt;STRONG&gt;scan&amp;nbsp;&lt;/STRONG&gt; to get the desired information (dataset name or number of observations or measured time).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In your code, you used function &lt;STRONG&gt;compress.&amp;nbsp;&lt;/STRONG&gt;Change it to function &lt;STRONG&gt;compbl&amp;nbsp;&lt;/STRONG&gt;or even skip it.&lt;/P&gt;
&lt;P&gt;Use function &lt;STRONG&gt;scan&amp;nbsp;&lt;/STRONG&gt; instead function &lt;STRONG&gt;substr.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Try it and come with your new code and results.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 May 2017 07:50:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Parse-SAS-Log-file/m-p/357082#M83797</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-05-09T07:50:11Z</dc:date>
    </item>
    <item>
      <title>Re: Parse SAS Log file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Parse-SAS-Log-file/m-p/357087#M83799</link>
      <description>&lt;P&gt;Concur with &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/88384"&gt;@Shmuel&lt;/a&gt;. use the index() and scan() functions; index() to detect the presence of a certain string, and scan() to extract a certain "word" from the string.&lt;/P&gt;
&lt;P&gt;The data step would look like that:&lt;/P&gt;
&lt;P&gt;- declare the infile with truncover and a end=done option&lt;/P&gt;
&lt;P&gt;- retain variables for datasetname, number of records and real time&lt;/P&gt;
&lt;P&gt;- set length for datasetname to $32&lt;/P&gt;
&lt;P&gt;- when you encounter a index(text,"NOTE: The data set") = 1, do:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; - if datasetname is already set (indicating that you've been collecting data already), output&lt;/P&gt;
&lt;P&gt;&amp;nbsp; - set datasetname with scan(text,5," ") and extract nrecs with nrecs = input(scan(text,7," ",best.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp; - set realtime to missing&lt;/P&gt;
&lt;P&gt;when you encounter "real time" in text, extract realtime like nrecs (experiment until you get the correct "word" number)&lt;/P&gt;
&lt;P&gt;when if done is true and datasetname &amp;gt; " ", output (to write the last occurence)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The check for the NOTEs from SQL look similar to that for a data step, just the words and positions are different&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 May 2017 08:19:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Parse-SAS-Log-file/m-p/357087#M83799</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-05-09T08:19:32Z</dc:date>
    </item>
    <item>
      <title>Re: Parse SAS Log file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Parse-SAS-Log-file/m-p/357336#M83871</link>
      <description>&lt;P&gt;Tried but in 2 steps.&lt;/P&gt;&lt;PRE&gt;data x_wo_step(keep= text ds_name ds_count real_time ) w_step(keep=ds_name step_used);
infile inn truncover end=eof;
input text $1000. ;
retain ds_name ds_count ;
if indexw(text,"NOTE: The data set") eq 1 then do;
ds_name = scan(text,5," ");
ds_count = scan(text,7," ");
output x_wo_step;
end;
else if indexw(text,"NOTE: Table") eq 1 then do;
ds_name = scan(text,3," ");
ds_count = scan(text,6," ");
output x_wo_step;
end;
else if indexw(text,'real') eq 1 then do; 
real_time = scan(text,3," "); 
output x_wo_step;
end;
else if indexw(text,'used') gt 1 then do;
step_used = scan(text,2," ")||""|| scan(text,3," "); /*--It's data/proc step --*/
output w_step;
end;
else do;
delete;
end;
run;
data x_wo_step_1;
set x_wo_step;
if real_time eq '' then delete;
run;
data Final_stats(drop=text);
merge x_wo_step_1(in=a) w_step(in=b);
by ds_name;
run;&lt;/PRE&gt;</description>
      <pubDate>Tue, 09 May 2017 23:22:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Parse-SAS-Log-file/m-p/357336#M83871</guid>
      <dc:creator>Saurabh13</dc:creator>
      <dc:date>2017-05-09T23:22:09Z</dc:date>
    </item>
    <item>
      <title>Re: Parse SAS Log file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Parse-SAS-Log-file/m-p/357383#M83888</link>
      <description>&lt;P&gt;My take would be this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data log (keep=datasetname nrecs realtime);
infile in truncover end=eof;
retain datasetname nrecs realtime;
format
  datasetname $32.
  nrecs comma12.
  realtime time11.2
;
input text $100.;
if index(text,"NOTE: The data set") = 1
then do;
  if datasetname ne " " then output;
  datasetname = scan(text,5," ");
  nrecs = input(scan(text,7," "),best.);
  realtime = .;
end;
else if index(text,"NOTE: Table") = 1
then do;
  if datasetname ne " " then output;
  datasetname = scan(text,3," ");
  nrecs = input(scan(text,6," "),best.);
  realtime = .;
end;
if index(text,"real time") &amp;gt; 0 then realtime = input(scan(text,3," "),best.);
if eof and datasetname ne " " then output;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Since PROC SQL issues a "Note: Table" for every dataset created, but only writes the statistics when it quits, one must not rely on "real time" for any output.&lt;/P&gt;
&lt;P&gt;Also note that your approach would create wrong data when the same dataset is created in several steps within one log file.&lt;/P&gt;</description>
      <pubDate>Wed, 10 May 2017 05:46:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Parse-SAS-Log-file/m-p/357383#M83888</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-05-10T05:46:29Z</dc:date>
    </item>
  </channel>
</rss>

