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
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 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"
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
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
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 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.