BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
SASuserlot
Barite | Level 11

I want to create a dataset like an image. It checks multiple datasets and gives information about which dataset has which variable. This dataset I eventually use it to export to keep track of variables present in all datasets. How can I achieve this? For this purpose, I am only giving two datasets, but these can sometimes be 20- 30 datasets. Thank you for your suggestions and tips

SASuserlot_0-1683816230981.png

 data have1;
 age = 12;
 name = "Ram";
 height =170;
 run;

 data have2;
 age = 12;
 name = "Ram";
 weight =156;
 run;

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

You might consider something like this to generate a report.

proc format;
value Myx
1='X'
other=' '
;
run;

proc tabulate data=sashelp.vcolumn;
   where libname='SASHELP' and memtype='DATA';
   class memname name;
   table memname,
         name*n=' '*f=myx. 
   ;
run;

The format is to place X in the report.

The SASHELP.Vcolumn view contains details of all the variables in all the datasets (memname) in all of the libraries currently assigned. The LIBNAME and MEMNAME are stored in uppercase when you want to filter.

If you only want specific data sets you could add a list such as: Memname in ('HAVE1' 'HAVE2') but if the interest is looking at many sets then the whole library approach may be preferred.

If I were going to have more variables (very likely) than data sets I recommend having the Name (variables) as the row and the data set (memname) as the columns. If you have 5 data sets with 500 variables the wide view is going to be frustrating.

 

I might also suggest including the variable TYPE so you could quickly identify the variables with the same name that have different types. That way you don't get surprised by messages about incompatible types

proc tabulate data=sashelp.vcolumn;
   where libname='YOURLIB' and memtype='DATA';
   class memname name type;
   table name*type,
         memname*n=' '*f=myx. 
   ;
run;

The SASHELP.VCOLUMN also has the bits about variable length, assigned format, informat, label, use in an index or sorted, the column position in the set so it is pretty easy to add such information to the report.

 

View solution in original post

9 REPLIES 9
PaigeMiller
Diamond | Level 26
proc sql;
    create table columns as select memname,name
    from sashelp.vcolumn
    where libname='WORK' and memname in ('HAVE1','HAVE2');
quit;
proc transpose data=columns out=columns_t(drop=_name_ _label_);
    by memname;
    var name;
    id name;
run;

 

Not exactly what you asked for, but if you absolutely must have 'X' in the cells (why?), a DATA step can fix that.

--
Paige Miller
SASuserlot
Barite | Level 11

Thanks, @PaigeMiller. It will do the job. I am keeping "X' to filter the column in Excel sheet but not mandatory. This will do the job; I just modified your code a little bit and used 'proc contents' ( with the help of a Friend) instead of the 'vcolumn' dataset. But the approach will be more efficient than mine.

 data have1;
 age = 12;
 name = "Ram";
 height =170;
 run;

 data have2;
 age = 12;
 name = "Ram";
 weight =156;
 run;

proc contents data= have1 out=chave1;
run;

proc contents data= have2 out=chave2;
run;
data chave3;
set chave1 chave2;
col = 'x';
run;

proc transpose data= chave3 out = thave3;
by memname;
var col;
id name;
run;

data want;
set have1 have2 indsname =b;
tblnmae1=b;
run;
SASuserlot
Barite | Level 11

I appreciate the reference. Is it mandatory to have the account( is it paid membership) to access the link?

Kurt_Bremser
Super User

With DATA step as first step, the "X" is simple:

data columns;
set sashelp.vcolumn; 
where libname = 'WORK' and memname in ('HAVE1','HAVE2');
v = "X";
keep memname name v;
run;

proc transpose data=columns out=columns_t(drop=_name_ _label_);
by memname;
var v;
id name;
run;
ballardw
Super User

You might consider something like this to generate a report.

proc format;
value Myx
1='X'
other=' '
;
run;

proc tabulate data=sashelp.vcolumn;
   where libname='SASHELP' and memtype='DATA';
   class memname name;
   table memname,
         name*n=' '*f=myx. 
   ;
run;

The format is to place X in the report.

The SASHELP.Vcolumn view contains details of all the variables in all the datasets (memname) in all of the libraries currently assigned. The LIBNAME and MEMNAME are stored in uppercase when you want to filter.

If you only want specific data sets you could add a list such as: Memname in ('HAVE1' 'HAVE2') but if the interest is looking at many sets then the whole library approach may be preferred.

If I were going to have more variables (very likely) than data sets I recommend having the Name (variables) as the row and the data set (memname) as the columns. If you have 5 data sets with 500 variables the wide view is going to be frustrating.

 

I might also suggest including the variable TYPE so you could quickly identify the variables with the same name that have different types. That way you don't get surprised by messages about incompatible types

proc tabulate data=sashelp.vcolumn;
   where libname='YOURLIB' and memtype='DATA';
   class memname name type;
   table name*type,
         memname*n=' '*f=myx. 
   ;
run;

The SASHELP.VCOLUMN also has the bits about variable length, assigned format, informat, label, use in an index or sorted, the column position in the set so it is pretty easy to add such information to the report.

 

SASuserlot
Barite | Level 11

 I wish I could 'PROC EXPORT" each of your brains into my head😀.  @ballardw @A_Kh @Kurt_Bremser @PaigeMiller @Reeza  thank you all for your suggestions and alternative ways to achieve this. Unfortunately, I can select one as "Answer". Each of your solutions works but I guarantee you guys covered most of anybody's requirements in this concept in the future. I really appreciate all of you guys.

A_Kh
Lapis Lazuli | Level 10

Another way is to use dictionary.columns. Advantage - you don't need to specify dataset names, only LIBRARY name is enough. It will give you all dataset names (in the directory) with the same variables. 

eg:

proc sql;
	select name 'Variable_Name', count(memname) 'Count', memname 'Dataset_name'
		from dictionary.columns
			where libname eq 'WORK'
		group by 1
       order by 1;
quit; 

output:
Capture.PNG

SAS Innovate 2025: Call for Content

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!

Submit your idea!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 9 replies
  • 1253 views
  • 6 likes
  • 6 in conversation