BookmarkSubscribeRSS Feed
UL
Calcite | Level 5 UL
Calcite | Level 5

Is there a way to generate a list of tables and columns that are referenced from SAS libraries? We've been generating these manually by scanning the SAS code but I am looking for a way how to do this programmatically.

9 REPLIES 9
tomrvincent
Rhodochrosite | Level 12
Load your code into a dataset and search for keywords that indicate tables or columns. Parse the lines for individual values. That would be a start.
UL
Calcite | Level 5 UL
Calcite | Level 5

Thanks Tom. Can this be done programmatically so that it populates a table, which has program name and table/column names used?

Reeza
Super User

@UL wrote:

Thanks Tom. Can this be done programmatically so that it populates a table, which has program name and table/column names used?


You can use SCAPROC to some degree, but if a program is a macro for example, then you definitely cannot parse the code. Unfortunately work like this is only really accurate if done manually. You can do scans but since it's not 100% you need to do a lot of verification, which is more work IME.

UL
Calcite | Level 5 UL
Calcite | Level 5

Thank you Reeza,

 

I am now looking at using the logging facility as an alternative to scanning the code. Do you think this approach is promising?

 

Here is the documentation from SAS: https://documentation.sas.com/?docsetId=logug&docsetTarget=p1ux9lxccgetcgn1hmkhm64m3ud0.htm&docsetVe...

Reeza
Super User

Not likely. How are you planning to deal with variable and data set lists?

Or macro code that generates dynamic variable or data set lists?

EDIT: It really depends on how accurate you need this to be. If you're okay with a high level of error, say 25-30% then I think these would be fine. If you're doing a migration or transition plan/project, then no, this will not be sufficient. 

You can't program your way out of bad documentation. 

 


@UL wrote:

Thank you Reeza,

 

I am now looking at using the logging facility as an alternative to scanning the code. Do you think this approach is promising?

 

Here is the documentation from SAS: https://documentation.sas.com/?docsetId=logug&docsetTarget=p1ux9lxccgetcgn1hmkhm64m3ud0.htm&docsetVe...




 

 

SuryaKiran
Meteorite | Level 14

Hello,

 

Welcome to SAS Community.

 

Are you trying to find the libraries and columns that your are using in your project or for the available ones? Querying the dictionary tables might be helpful (dictionary.tables and dictionary.columns)

Thanks,
Suryakiran
UL
Calcite | Level 5 UL
Calcite | Level 5

Hi Suryakiran,

 

Thank you for your reply. I'm trying to find the columns that are used. Not the available ones. I wonder whether it is possible to generate a list like this:

 

SAS Program name ABC uses

 column Database1.Schema1.Table1.Column1

and Database1.Schema1.Table1.Column2

and Database1.Schema1.Table1.Column5

and Database1.Schema1.Table5.Column1

and Database2.Schema1.Table1.Column1

etc.

ballardw
Super User

@UL wrote:

Hi Suryakiran,

 

Thank you for your reply. I'm trying to find the columns that are used. Not the available ones. I wonder whether it is possible to generate a list like this:

 

SAS Program name ABC uses

 column Database1.Schema1.Table1.Column1

and Database1.Schema1.Table1.Column2

and Database1.Schema1.Table1.Column5

and Database1.Schema1.Table5.Column1

and Database2.Schema1.Table1.Column1

etc.


By database above are you referencing external database such as Oracle or Teradata? That would add some complexity depending on the database system and how you are referencing things.

SuryaKiran
Meteorite | Level 14

I don't think there is a straight forward approach for this, you may need to develop your own logic. Even though if you scan your .sas file, what if there is a select * program that selects all of the columns. Those columns names are not listed in the program but you are utilizing them.

Thanks,
Suryakiran

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!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 9 replies
  • 1588 views
  • 5 likes
  • 5 in conversation