BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jordanw1993
Fluorite | Level 6

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

1 ACCEPTED SOLUTION

Accepted Solutions
jordanw1993
Fluorite | Level 6

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

4 REPLIES 4
TomKari
Onyx | Level 15

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"

jordanw1993
Fluorite | Level 6

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

TomKari
Onyx | Level 15

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

jordanw1993
Fluorite | Level 6

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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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