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
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.
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.
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.
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!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.