DATA Step, Macro, Functions and more

Search for library references in the SAS code inside dataset

Reply
Contributor
Posts: 52

Search for library references in the SAS code inside dataset

[ Edited ]

Hi,

 

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:

lib_name:
mkis
cad
cad
cdd
mkis
focus

 

 

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.

 

Manjeet 


Cheers from India!

Manjeet
Super User
Super User
Posts: 7,955

Re: Search for library references in the SAS code inside dataset

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

http://www2.sas.com/proceedings/forum2008/006-2008.pdf

(Source Code Analyser Procedure).

 

Contributor
Posts: 52

Re: Search for library references in the SAS code inside dataset

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.

 

for example:

 

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;

Cheers from India!

Manjeet
Super User
Super User
Posts: 7,955

Re: Search for library references in the SAS code inside dataset

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.

Contributor
Posts: 52

Re: Search for library references in the SAS code inside dataset

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.


Cheers from India!

Manjeet
Super User
Posts: 5,429

Re: Search for library references in the SAS code inside dataset

Yes it runs the code, but why not? You want the I information so it shouldn't matter how you get it...
I know that's not the issue but I'm just curious: why do you store SAS programs in a data set? What advantage does that give?
Data never sleeps
Ask a Question
Discussion stats
  • 5 replies
  • 149 views
  • 1 like
  • 3 in conversation