Desktop productivity for business analysts and programmers

Finding a specific variable into any libraries and dataset

Accepted Solution Solved
Reply
Regular Contributor
Posts: 168
Accepted Solution

Finding a specific variable into any libraries and dataset

Good morning,

 

I am working for an organization that has little information on datasets and libraries as well.

 

I am looking a fast way to localize a specific variable in any dataset and any libraries.

 

Does someone has ever work on this problem?

Regards,

 

Alain


Accepted Solutions
Solution
‎03-20-2018 07:43 AM
Super User
Posts: 13,932

Re: Finding a specific variable into any libraries and dataset

This would find all instances of a variable with the name you specify in data sets that are assigned to libraries. The upcase is used because the variable name that holds the variable name may be of mixed case. So use Upcase on the variable and provide an all upper case version of the variable you are searching for.

 

proc sql;
   create table variableinfo as
   select * 
   from dictionary.columns
   where upcase(name)='YOURVARIABLE'
   ;
quit;

If you are looking for a few variables then use this where

 

where upcase(name) in ('YOURVARIABLE' 'OTHERVAR' 'PDQ')

If you have many variables of interest it may be best to place them into a data set, one variable per record and use something like

 

proc sql;
   create table variableinfo as
   select b.* 
   from variablenameset as a
        left join
        dictionary.columns as b
        on upcase(a.vname) = upcase(b.name)
   ;
quit;

But this approach relies on the datasets being in currently define libraries.

 

View solution in original post


All Replies
Super User
Posts: 10,568

Re: Finding a specific variable into any libraries and dataset

If you can be sure that all directories that contain .sas7bdat files are assigned a library in your current session, then looking for your variable in dictionary.columns should do it.

 

If not, then you will have to make a file search for .sas7bdat files, convert the result to a dataset, and either run proc contents for all datasets that are not in an assigned library, or assign temporary libraries so that you can use dictionary.columns. I know that sometime in the past few months I posted an example for something similar here.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Solution
‎03-20-2018 07:43 AM
Super User
Posts: 13,932

Re: Finding a specific variable into any libraries and dataset

This would find all instances of a variable with the name you specify in data sets that are assigned to libraries. The upcase is used because the variable name that holds the variable name may be of mixed case. So use Upcase on the variable and provide an all upper case version of the variable you are searching for.

 

proc sql;
   create table variableinfo as
   select * 
   from dictionary.columns
   where upcase(name)='YOURVARIABLE'
   ;
quit;

If you are looking for a few variables then use this where

 

where upcase(name) in ('YOURVARIABLE' 'OTHERVAR' 'PDQ')

If you have many variables of interest it may be best to place them into a data set, one variable per record and use something like

 

proc sql;
   create table variableinfo as
   select b.* 
   from variablenameset as a
        left join
        dictionary.columns as b
        on upcase(a.vname) = upcase(b.name)
   ;
quit;

But this approach relies on the datasets being in currently define libraries.

 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 169 views
  • 2 likes
  • 3 in conversation