Desktop productivity for business analysts and programmers

Parse SCAPROC log file using regular expressions

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 7
Accepted Solution

Parse SCAPROC log file using regular expressions

Hi Everyone, 

 

I am trying to parse all libnames and library paths from a log created with SCAPROC. I have been succesful parsing the dataset names using the following code:

 

data output_files_&code_type.;
infile scalog truncover;
input @1 logline $256.;
keep libname filename;
retain prx_output_file;
if _n_=1 then do;
prx_output_file = prxparse("!\bJOBSPLIT: DATASET OUTPUT \b.*\b (\b.*\b) \*/!");
end;
if prxmatch(prx_output_file, logline) > 0 then do;
filename_full=prxposn(prx_output_file,1,logline);
libname=scan(filename_full,1);
filename=scan(filename_full,2);
output output_files_&code_type.;
end;
run;

 

However I am receiving no regular expression matches for the following code:

 

data output_lib_&code_type.;
infile scalog truncover;
input @1 logline $256.;
keep filepath libname;
retain prx_output_lib;
if _n_=1 then do;
prx_output_lib = prxparse("!\bJOBSPLIT: LIBNAME (\b.*\b) ("('[^"]')*") \*/!");
end;
if prxmatch(prx_output_lib, logline) > 0 then do;
libname=prxposn(prx_output_lib,1,logline);
filepath=prxposn(prx_output_lib,2,logline);
output output_lib_&code_type.;
end;
run;

 

I have succesfully tested the regular expression(in bold) in a browser based editor which returns the libname in capture group 1 and the pathname in capture group 2. An example of the SCAPROC logline I would like to parse is below:

 

/* JOBSPLIT: LIBNAME LMCOMSYS "/team/Common/System/v1.00.3" access=readonly */

 

Would anyone be able to point out where I am going wrong in SAS?

Thanks,

Jordan


Accepted Solutions
Solution
2 weeks ago
Occasional Contributor
Posts: 7

Re: Parse SCAPROC log file using regular expressions

Hi Tom,

 

I have come to a solution that works with the following expression:

prx_output_lib = prxparse("!\bJOBSPLIT: LIBNAME (\S+) ""([^""]+)"" \S+!");

Thanks for pointing me in the right direction!

Jordan

View solution in original post


All Replies
PROC Star
Posts: 1,288

Re: Parse SCAPROC log file using regular expressions

Posted in reply to jordanw1993

This works for me:

 

prx_output_lib = prxparse("!\bJOBSPLIT: LIBNAME (\S+) ""([^""]+)"" \S+ \*\/!");

 

Tom

 

"Greater love hath no man for his friend than that he will debug his RX problems"

Occasional Contributor
Posts: 7

Re: Parse SCAPROC log file using regular expressions

Hi Tom,

 

Thanks for looking into this. It appears the solution won't work for me. I'm running the following code:

 

data output_lib;
    infile scalog truncover;
    input @1 logline $256.;
    keep filepath lib_name;
    retain prx_output_lib;
    if _n_=1 then do;
        prx_output_lib = prxparse("!\bJOBSPLIT: LIBNAME (\S+) ""([^""]+)"" \S+ \*\/!");
    end;
    if prxmatch(prx_output_lib, logline) > 0 then do;
        lib_name=prxposn(prx_output_lib, 1 , logline);
        filepath=prxposn(prx_output_lib, 2 , logline);
    output output_lib;
    end;
run;

 

NOTE: The data set WORK.OUTPUT_LIB has 0 observations and 2 variables.

Would you be able to tell me why 'lib_name' and 'filepath' aren't being populated with the first and second capture group respectively?

I'm using SAS EG version 7.13 HF5 (7.100.3.5486) (32-bit)

 

I can populate the variables 'libname' and 'filename' successfully using the first datastep in my original post, which parses the following string:
/* JOBSPLIT: DATASET OUTPUT SEQ TESTA.DSET1.DATA */


Thanks for your help so far,
Jordan

PROC Star
Posts: 1,288

Re: Parse SCAPROC log file using regular expressions

Posted in reply to jordanw1993

The data line that you're parsing in this post has a completely different structure. There are no double quotes, and there are two tokens between your libname and your filepath.

 

You're going to need to examine all of your JOBSPLIT entries, and figure out what kind of conditional logic you'll need to correctly parse them. Otherwise you'll go mad trying to deal with one exception after another. This can be tricky, I'll warn you.

 

Tom

Solution
2 weeks ago
Occasional Contributor
Posts: 7

Re: Parse SCAPROC log file using regular expressions

Hi Tom,

 

I have come to a solution that works with the following expression:

prx_output_lib = prxparse("!\bJOBSPLIT: LIBNAME (\S+) ""([^""]+)"" \S+!");

Thanks for pointing me in the right direction!

Jordan

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 155 views
  • 0 likes
  • 2 in conversation