Last active
November 30, 2017 17:28
-
-
Save statgeek/3b57ae085d9f7a36a2d95c15f04e72e6 to your computer and use it in GitHub Desktop.
SAS - create a table that shows which variables are in which datasets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
*Here's a bit of a long way to generate the list of datasets with variables present. | |
This program looks at ALL variables, to restrict it to a select list, see the line of | |
code to be modified via the comments.; | |
/*Generate fake data to work with*/ | |
data class1; | |
set sashelp.class; | |
drop age sex; | |
run; | |
data class2; | |
set sashelp.class; | |
drop weight height; | |
run; | |
data class3; | |
set sashelp.class; | |
Order=1; | |
run; | |
data class4; | |
set sashelp.class; | |
keep name; | |
run; | |
data class5; | |
set sashelp.class; | |
run; | |
/*Extract metadata from dictionary tables*/ | |
proc sql noprint; | |
create table column_list as select memname, libname, name, type, 1 as count | |
from dictionary.columns where libname='WORK' and memname like 'CLASS%' | |
/*ADD THE VARIABLE LIST HERE*/ | |
order by memname, name; | |
quit; | |
/*Transpose results to a more user friendly format*/ | |
proc transpose data=column_list out=flipped; | |
by memname; | |
id name; | |
idlabel name; | |
var count; | |
run; | |
/*Format output*/ | |
data want; | |
retain memname; | |
set flipped; | |
array class(*) _NUMERIC_; | |
do i=1 to dim(class); | |
if class(i)=. then | |
class(i)=0; | |
end; | |
All_Variables=sum(of _numeric_)-I; | |
DROP I _NAME_; | |
run; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment