|
|
|
How do I search for all occurrences of a column?
|
The macro "Search_for_Column" uses Dictionary tables to find all occurrences of a column that
matches the string provided in any of the LIBNAMEs currently assigned. It has also been written to
allow you to search certain LIBNAMEs only or to exclude LIBNAMEs.
%macro Search_for_Column(COLUMN,
SELECT =,
EXCLUDE = 'SASHELP' 'MAPS') ;
%* COLUMN : A Positional Parameter where you provide the name of the
column to search for enclosed in single quotes.
Wild card characters compatible with the LIKE operator can
also be used (i.e. % any characters, _ single character).
SELECT : List of LIBNAMEs to search for, remember to enclose each
libname in single quotes.
EXCLUDE: List of LIBNAMEs to NOT search for, remember to enclose each
libname in single quotes. The LIBNAMEs SASHELP and MAPS are
excluded by default. The EXCLUDE parameter will be ignored
if the SELECT parameter is used. ;
%* To allow the SELECT parameter to take precedence over the EXCLUDE
parameter ;
%local where title ;
%if &select ne %then
%do ;
%let where = and libname in (%upcase(&select)) ;
%let title = Search Limited to LIBNAMEs: &select ;
%end ;
%else
%if &exclude ne %then
%do ;
%let where = and libname not in (%upcase(&exclude)) ;
%let title = Search Excludes the LIBNAMEs: &exclude ;
%end ;
%* Use %SUPERQ to mask '%', '&' and quotes in the title statement ;
proc sql ;
title1 "Tables that contain a column like %superq(column)" ;
title2 "%superq(title)" ;
select Libname, Memname, Name
from dictionary.columns
where upcase(name) like %upcase(&column)
&where ;
quit ;
%mend Search_for_Column ;
%* Search all columns that have the string DATE in their name but do not
search the libraries SASHELP or MAPS. ;
%Search_for_Column('%date%')
%* Search all columns that have the string DATE in their name within the
SASHELP library only. ;
%Search_for_Column('date', select= 'sashelp' )
%* Search all columns that have any two characters followed by the
string DATE within all assigned libraries. ;
%Search_for_Column('__date', exclude= )
Note: The above code has been tested using SAS 8.2 on the Windows operating system.
|