BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Billybob73
Quartz | Level 8

Hi,
I'm in a situation that I've thousands of SAS datasets scattered all over both the LAN and the SAS Server.
These datasets are not necessarily in SAS libraries.
Is there a way to get their metadata in a loop ?
In a huge table I need information per dataset such as variable, type, length, varnum, format
Thanks !
Regards
B.

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

On UNIX, I'd run

find / -name \*.sas7bdat > /tmp/dataset.list

From the list file, read the physical filenames. Use string functions to extract the pathname and the dataset name.

From dictionary.libnames (SQL) get the physical path names and logical libnames.

Merge those datasets by physical path.

Create a macro that retrieves the information you want (for a single dataset):

%macro get_meta(libname,memname,physical);
%if "&physical" ne ""
%then %do;
  libname &libname "&physical";
%end;

proc contents
  data=&libname..&memname
  out=temp
  noprint
;
run;

proc append data=temp base=target.mymetadata;
run;

%if "&physical" ne ""
%then %do;
  libname &libname clear;
%end;

%mend;

Run that macro off your dataset of datasets with call execute:

data _null_;
set mydatasets;
/* insert a where condition to exclude predefined libraries like WORK, SASUSER, SASHELP etc */
if libname = ""
then call execute('%nrstr(%get_meta)(__TEMP,' !! trim(memname) !! ',' !! trim(physical_path) !! ');');
else call execute('%nrstr(%get_meta)(' !! trim(libname) !! ',' !! trim(memname) !! ');');
run;

Be aware that you need to have the necessary permissions; it's best to run the find as superuser, so you get no error messages for inaccessible directories that are not of interest anyway (like /etc/security, where you will not find any SAS datasets). The same goes for all directories where datasets are found.

View solution in original post

4 REPLIES 4
Reeza
Super User

You can assign a library, then you can grab the data from SASHELP.VCOLUMN. 

 

I would probably first check my library locations, scan my LAN for SAS7BDAT files using an OS approach (or see SAS Macro Appendix for a macro that does this). Check if any folders don't match your libraries from (SASHELP.VLIBNAM) and assign those libraries. Once that's done you can pull all your data from SASHELP.VCOLUMN. 

ballardw
Super User

For added fun are any of these sets in older SAS formats such as SSD or SD2 extensions?

Kurt_Bremser
Super User

On UNIX, I'd run

find / -name \*.sas7bdat > /tmp/dataset.list

From the list file, read the physical filenames. Use string functions to extract the pathname and the dataset name.

From dictionary.libnames (SQL) get the physical path names and logical libnames.

Merge those datasets by physical path.

Create a macro that retrieves the information you want (for a single dataset):

%macro get_meta(libname,memname,physical);
%if "&physical" ne ""
%then %do;
  libname &libname "&physical";
%end;

proc contents
  data=&libname..&memname
  out=temp
  noprint
;
run;

proc append data=temp base=target.mymetadata;
run;

%if "&physical" ne ""
%then %do;
  libname &libname clear;
%end;

%mend;

Run that macro off your dataset of datasets with call execute:

data _null_;
set mydatasets;
/* insert a where condition to exclude predefined libraries like WORK, SASUSER, SASHELP etc */
if libname = ""
then call execute('%nrstr(%get_meta)(__TEMP,' !! trim(memname) !! ',' !! trim(physical_path) !! ');');
else call execute('%nrstr(%get_meta)(' !! trim(libname) !! ',' !! trim(memname) !! ');');
run;

Be aware that you need to have the necessary permissions; it's best to run the find as superuser, so you get no error messages for inaccessible directories that are not of interest anyway (like /etc/security, where you will not find any SAS datasets). The same goes for all directories where datasets are found.

Billybob73
Quartz | Level 8

Hi Kurt,

This is the way to do it ! Thanks !!

Rgds

B

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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
  • 4 replies
  • 1272 views
  • 3 likes
  • 4 in conversation