01-16-2017 06:57 AM - edited 01-16-2017 06:57 AM
I am looking for one answer. I am not very good at regular expressions and prxmatch.
I have the full sas code in our dataset. I need to find out the library refernces for that dataset- have and create a dataset- want which will have all the library references excluding the 'work'. also it should look for other code as well and not just proc sql queries.
the code should also exclude all the other code.
Output required is in dataset want:
Data have; length query $200; infile datalines truncover; input query $char100.; datalines4; Proc SQL; create table t1 as select a from mkis.ba, cad.bb,work.dd; quit; /* this is comment */ data abc; set cad.old; run; Proc SQL; create table t2 as select a from cad.t3 inner join work.t4 on t3.id=t4.Id ; quit; Proc SQL; create table t5 as select a from mkis.t6 left join work.t7 on t6.id=t8.id left join focus.t8 on t6.id=t8.id; quit; ;;;; ; ;;;;;;; run;
thanks in advance.
01-16-2017 07:24 AM
Don't bother trying to write a code parser yourself, its a very complex thing. SAS provides functionality to do this now, it is by using the proc scaproc
(Source Code Analyser Procedure).
01-16-2017 11:16 PM
I am not trying to parse the code here, i just wanted to find out the table/library name from the code in the dataset. i need to use those libraries to define their libname statements.
Proc SQL; create table t1 as select a from mkis.ba, cad.bb,work.dd; quit;
from the above code, i need to identify the 2 libaries- mkis and cad and write out their library name reference statemnts.
libname mkis "C0042.bsa.bsa.mkis.sas" disp=shr;
01-17-2017 04:10 AM
Yes, you are trying to parse the text here. Libraries and their use can come in many forms, have aliases, be used in includes, be used in macros etc. As I have said, it is a complex task, and a needless one as there is a procedure already designed for the task, called proc scaproc.
01-17-2017 06:42 AM
thanks for the reply.
PROC SCAPROC only works when you run the code right? We are actually migrating the code from SAS EG to base sas, so we have captured all the sas code inside a dataset, one sentence of sas code as one observation.
I am not running the sas code, this sas code is inside a dataset and code will be in turn return to the one sas file, including the library refernces if we are able to find one.
01-17-2017 11:24 AM