Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

accessed datasets 1

Status
Not open for further replies.

SASfan

Programmer
Nov 6, 2008
2
DE
hi all together,

is there a sas statement, that lists the datasets a sas-programm needs and has access to?


thanks a lot for your help.

background:

I have to check round about 500 sas programms, which data sets which programm needs. It would be great, if SAS could automate this boring job.
 
Unfortunately no, there's no procedure for this.

However, what you COULD do it write a SAS program that reads other SAS programs as text files and collects the info that you need.

First up you'll be interested in lines starting with SET, MERGE or DATA and lines starting with PROC.
With PROCs, life is a little more complicated, you'll want to find a DATA= statement, OR a CREATE TABLE statement.

Also, you'll want to collect the LIBNAME statements so you know what libraries are being used.

One other item that can help is using dictionary tables.
You can use this:-
Code:
proc sql;
  create table TABLES as
  select *
  from dictionary.tables
  where LIBNAME = "<your lirbary name>"
  ;
quit;
to get a list of the tables/datasets in <your library name>.

Build the code up slowly piece by piece and test each component as you do it. Shouldn't be more than a days work to get a working version that'll do alot of the grunt work for you.

Watch out for proc sql steps, they'll be a little more problematic, also watching out for DATA, SET and MERGE statements which reference multiple datasets (keep reading to the ; mark, ignore anything in brackets).

Might also be worth doing a google search for an example. Something like "SAS code scan" or something might get some results.
Let us know how you do, this is actually a project I've been thinking about tackling several times over the last few years, but never had the need to do it, and therefore never had the motivation to do it.

Chris
Business Analyst, Code Monkey, Data Wrangler.
SAS Guru.
 
hi chris,

thanks for your reply.

unfortunately, the reason why i was searching for an ready-made sas statement was, that i already tried to do the yob via vba. Indeed, SAS would also work, but i canceled the approach due to too many oddments.

(for example just reading a data step with more than one dataset and some options data set1 set2 set3 opt1 opt2...;
would cause problems in regards to how the compiler should recognize, which data set is the last to read and where does the first option begin...) furthermore there are a lot of macros in the code and being honest i am not that familiar with macro-programming ... so i do not know when they reference a data set and when not.


it seems as if I'll have to go the long way (searching manually and copying to excel...)


but anyway thanks a lot and kind regards
stefan
 
As an alternative, you can run the SAS program and add something like this to the end of it.
Code:
proc sql noprint;
  select distinct "'" || trim(libname) || "'"
  into :LIBS separated by ','
  from dictionary.libnames
  where libname not in('MAPS','SASHELP','SASUSER')
  ;
quit;
%put libnames = &LIBS;

proc sql;
  create table tables as
  select *
  from dictionary.tables
  where libname in(&LIBS)
  ;
quit;

proc print data=tables;
run;
That'll leave you with a list of every table that is accessible, or created by the program.
You'll probably want to use an ODS output for the proc print as it won't look great in the list output, you can use the EXCELXP tagset to output that directly to Excel, which will at least save you a fair amounnt of copying and pasting.
One of the columns that'll be written out for you by the proc print shows when the dataset was created, which should also be useful.

Chris
Business Analyst, Code Monkey, Data Wrangler.
SAS Guru.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top