DATA Step, Macro, Functions and more

Bulk Query View Definitions.

Reply
Occasional Contributor
Posts: 8

Bulk Query View Definitions.

Hi There,

 

I've been racking my brains all morning trying to figure this one out.

Is there a way to query the definition of a view, for example I want to know how many views in my library use a particular table/dataset.

 

Proc Sql;

Create Table Views as

Select *

From <ViewDefs>

Where ViewName = 'MyView'

and DefCol like '%datasetname%'

;

Quit;

 

Thank you in advance.

 

Super User
Posts: 5,257

Re: Bulk Query View Definitions.

Tha's a great question!

Unfortunately, I'm not aware of any out-of-box functionality for this.

But it would good thought, like in SQL Server where you can see dependencies of a view directly.

 

So, perhaps you need to parse all view definitions (looking for keywords like from, join etc).

But then you might have data step views...

 

When dealing with larger implementations, I usually have access to metadata tool, in SAS that would be DI Studio. Then you create the metadata first, then create any view/table with code derived directly from metadata.

Data never sleeps
SAS Super FREQ
Posts: 683

Re: Bulk Query View Definitions.

Hi To query which views are available you can use DICTIONARY.VIEWS.

 

As @LinusH pointed out, to actually figure out what tables and columns are coming from which tables/views you need to parse the output of the DESCRIBE statement from Proc SQL or the DATA Step.

 

Below are some code examples:

data work.ds_view / view=work.ds_view;
  set sashelp.cars;
run;

proc sql;
  create table myviews as
  select
    *
  from
    dictionary.views
  ;
quit;

proc sql;
  describe view SASHELP.VTABLE;
quit;

data view=work.ds_view;
  describe;
run;

Bruno

Ask a Question
Discussion stats
  • 2 replies
  • 157 views
  • 2 likes
  • 3 in conversation