BookmarkSubscribeRSS Feed
upadhi
Quartz | Level 8

Hi team,

I have scanned a SAS code and able to able the proc sql statements in a table for example:

Line

proc sql;
create table x as select * from lib1.tab1 , lib2.tab2 where a=b;
create table x as select * from lib1.tab1 left join lib2.tab2 on a=b;
quit;

 

Next is i want to extract the library and table names from each of these line items. I understand we would need a recursive code as there can be multiple tables in from. Can anyone help me here

2 REPLIES 2
ballardw
Super User

 

You may need to answer some questions before anyone takes a stab at this.

First is the code ONLY, and I mean only, Proc SQL code?

Second, are all of the libraries that might be encountered defined in the session that will be searching for the data sets?

Third, do you need to identify WORK or USER library data sets?

 

The reason why these two questions are important because the main way that would be used to identify such are the lll.dddddd strings of library name and data set name. However that same construct is used in the data step with Hash objects, First. and Last. coding in data step, the Report Writing Interface coding and other places. If only Proc SQL code is involved then there is some chance.

With the advent of ODS OUTPUT statements you can't be sure that data sets always follow a very small number of key words like "create table" or "output=" or "out=". Macro coding can also seriously complicate identifying actual library and dataset names when they are build dynamically.

 

If other procedures and data step coding is involved then the only way to identify if a specific ABC. references a library named may be if the library is defined in the current session.

 

And last, if WORK or USER datasets need to be identified when single level names are used then the issue may get a bit more complicated because you have to assign the library when encountering possible data sets.

 

If the code is being run routinely you might investigate use of Proc SCAPROC which captures a lot of information about code as it runs and writes it into a text file. The text file would have searchable strings identifying output or input data sets.

upadhi
Quartz | Level 8

thanks for your reply. ideally i have to scan all procs and data steps.

i want something like this:

 

string: my aim is to find every word after BANK.upa for every bank.xx in this line bank.ff

output: upa xx ff

 

how can i extract the same

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 2 replies
  • 915 views
  • 0 likes
  • 2 in conversation