<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Loop through thousands of SAS datasets for metadata in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Loop-through-thousands-of-SAS-datasets-for-metadata/m-p/433050#M107326</link>
    <description>&lt;P&gt;Hi Kurt,&lt;/P&gt;&lt;P&gt;This is the way to do it ! Thanks !!&lt;/P&gt;&lt;P&gt;Rgds&lt;/P&gt;&lt;P&gt;B&lt;/P&gt;</description>
    <pubDate>Thu, 01 Feb 2018 09:26:45 GMT</pubDate>
    <dc:creator>Billybob73</dc:creator>
    <dc:date>2018-02-01T09:26:45Z</dc:date>
    <item>
      <title>Loop through thousands of SAS datasets for metadata</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-through-thousands-of-SAS-datasets-for-metadata/m-p/432533#M107143</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;I'm in a situation that I've thousands of SAS datasets scattered all over both the LAN and the SAS Server.&lt;BR /&gt;These datasets are not necessarily in SAS libraries.&lt;BR /&gt;Is there a way to get their metadata in a loop ?&lt;BR /&gt;In a huge table I need information per dataset such as variable, type, length, varnum, format&lt;BR /&gt;Thanks !&lt;BR /&gt;Regards&lt;BR /&gt;B.&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jan 2018 22:02:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-through-thousands-of-SAS-datasets-for-metadata/m-p/432533#M107143</guid>
      <dc:creator>Billybob73</dc:creator>
      <dc:date>2018-01-30T22:02:16Z</dc:date>
    </item>
    <item>
      <title>Re: Loop through thousands of SAS datasets for metadata</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-through-thousands-of-SAS-datasets-for-metadata/m-p/432535#M107144</link>
      <description>&lt;P&gt;You can assign a library, then you can grab the data from SASHELP.VCOLUMN.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jan 2018 22:09:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-through-thousands-of-SAS-datasets-for-metadata/m-p/432535#M107144</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-01-30T22:09:35Z</dc:date>
    </item>
    <item>
      <title>Re: Loop through thousands of SAS datasets for metadata</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-through-thousands-of-SAS-datasets-for-metadata/m-p/432563#M107149</link>
      <description>&lt;P&gt;For added fun are any of these sets in older SAS formats such as SSD or SD2 extensions?&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jan 2018 23:25:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-through-thousands-of-SAS-datasets-for-metadata/m-p/432563#M107149</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-01-30T23:25:10Z</dc:date>
    </item>
    <item>
      <title>Re: Loop through thousands of SAS datasets for metadata</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-through-thousands-of-SAS-datasets-for-metadata/m-p/432631#M107172</link>
      <description>&lt;P&gt;On UNIX, I'd run&lt;/P&gt;
&lt;PRE&gt;find / -name \*.sas7bdat &amp;gt; /tmp/dataset.list&lt;/PRE&gt;
&lt;P&gt;From the list file, read the physical filenames. Use string functions to extract the pathname and the dataset name.&lt;/P&gt;
&lt;P&gt;From dictionary.libnames (SQL) get the physical path names and logical libnames.&lt;/P&gt;
&lt;P&gt;Merge those datasets by physical path.&lt;/P&gt;
&lt;P&gt;Create a macro that retrieves the information you want (for a single dataset):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro get_meta(libname,memname,physical);
%if "&amp;amp;physical" ne ""
%then %do;
  libname &amp;amp;libname "&amp;amp;physical";
%end;

proc contents
  data=&amp;amp;libname..&amp;amp;memname
  out=temp
  noprint
;
run;

proc append data=temp base=target.mymetadata;
run;

%if "&amp;amp;physical" ne ""
%then %do;
  libname &amp;amp;libname clear;
%end;

%mend;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Run that macro off your dataset of datasets with call execute:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;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;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;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.&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jan 2018 08:13:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-through-thousands-of-SAS-datasets-for-metadata/m-p/432631#M107172</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-01-31T08:13:47Z</dc:date>
    </item>
    <item>
      <title>Re: Loop through thousands of SAS datasets for metadata</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-through-thousands-of-SAS-datasets-for-metadata/m-p/433050#M107326</link>
      <description>&lt;P&gt;Hi Kurt,&lt;/P&gt;&lt;P&gt;This is the way to do it ! Thanks !!&lt;/P&gt;&lt;P&gt;Rgds&lt;/P&gt;&lt;P&gt;B&lt;/P&gt;</description>
      <pubDate>Thu, 01 Feb 2018 09:26:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-through-thousands-of-SAS-datasets-for-metadata/m-p/433050#M107326</guid>
      <dc:creator>Billybob73</dc:creator>
      <dc:date>2018-02-01T09:26:45Z</dc:date>
    </item>
  </channel>
</rss>

