<?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 LIBNAME error trapping? in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/LIBNAME-error-trapping/m-p/238132#M55405</link>
    <description>&lt;P&gt;Hello all,&lt;/P&gt;
&lt;P&gt;I am working with a lot of metadata, opening thousands of different db files: access, sas, dbf, and more.&amp;nbsp; I wanted to add a feature that traps my errors not in the log file but in a new data set or on the master list of my list of files indicateing I had an error opening/connecting the LIBNAME. Does anyone have any starter code on this?&amp;nbsp; Any help would be greatly apresheated for a new SAS guy (April/May2015).&amp;nbsp;&amp;nbsp; TIA. -KJ&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ERROR: Connect: Could not find file 'D:\MyPath\MyMdb.MDB'.&lt;BR /&gt;ERROR: Error in the LIBNAME statement.&lt;/P&gt;</description>
    <pubDate>Mon, 07 Dec 2015 18:51:49 GMT</pubDate>
    <dc:creator>kjohnsonm</dc:creator>
    <dc:date>2015-12-07T18:51:49Z</dc:date>
    <item>
      <title>LIBNAME error trapping?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/LIBNAME-error-trapping/m-p/238132#M55405</link>
      <description>&lt;P&gt;Hello all,&lt;/P&gt;
&lt;P&gt;I am working with a lot of metadata, opening thousands of different db files: access, sas, dbf, and more.&amp;nbsp; I wanted to add a feature that traps my errors not in the log file but in a new data set or on the master list of my list of files indicateing I had an error opening/connecting the LIBNAME. Does anyone have any starter code on this?&amp;nbsp; Any help would be greatly apresheated for a new SAS guy (April/May2015).&amp;nbsp;&amp;nbsp; TIA. -KJ&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ERROR: Connect: Could not find file 'D:\MyPath\MyMdb.MDB'.&lt;BR /&gt;ERROR: Error in the LIBNAME statement.&lt;/P&gt;</description>
      <pubDate>Mon, 07 Dec 2015 18:51:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/LIBNAME-error-trapping/m-p/238132#M55405</guid>
      <dc:creator>kjohnsonm</dc:creator>
      <dc:date>2015-12-07T18:51:49Z</dc:date>
    </item>
    <item>
      <title>Re: LIBNAME error trapping?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/LIBNAME-error-trapping/m-p/238141#M55406</link>
      <description>&lt;P&gt;I suggest you check out the LIBNAME function which will allow you to trap return codes and error messages:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/lefunctionsref/67960/HTML/default/viewer.htm#p1bq8nyxm7y1ygn1i4vyf82z68ls.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lefunctionsref/67960/HTML/default/viewer.htm#p1bq8nyxm7y1ygn1i4vyf82z68ls.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Dec 2015 19:20:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/LIBNAME-error-trapping/m-p/238141#M55406</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2015-12-07T19:20:47Z</dc:date>
    </item>
    <item>
      <title>Re: LIBNAME error trapping?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/LIBNAME-error-trapping/m-p/238164#M55412</link>
      <description>&lt;P&gt;Is this remotly close?&lt;/P&gt;
&lt;P&gt;for my program:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LIBNAME MYMDB ACCESS PATH="D:\MyDir\MyFile.MDB" access=readonly;&lt;/P&gt;
&lt;P&gt;works and I can get my metadata.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;when I try to addapt it to this web page sample:&lt;/P&gt;
&lt;PRE class="xis-code"&gt;%let mylib=c:\projects\May2015;
%if %sysfunc(libname(new,&amp;amp;mylib)) %then
%put %sysfunc(sysmsg());&lt;BR /&gt;&lt;BR /&gt;&lt;/PRE&gt;
&lt;P&gt;I come up with this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let myfile='D:\MyDir\MyFile.MDB';&lt;BR /&gt;%if %sysfunc(libname('MYMDB', 'ACCESS', &amp;amp;myfile, 'readonly')) %then&lt;BR /&gt;%put %sysfunc(sysmsg());&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and get this error:&lt;/P&gt;
&lt;P&gt;ERROR: The %IF statement is not valid in open code.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am not sure what to try, I have tryied adding and removing quotes on the arguments.&lt;/P&gt;</description>
      <pubDate>Mon, 07 Dec 2015 21:01:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/LIBNAME-error-trapping/m-p/238164#M55412</guid>
      <dc:creator>kjohnsonm</dc:creator>
      <dc:date>2015-12-07T21:01:27Z</dc:date>
    </item>
    <item>
      <title>Re: LIBNAME error trapping?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/LIBNAME-error-trapping/m-p/238183#M55414</link>
      <description>&lt;P&gt;To use a %IF statement it must be inside a macro. Try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro Assign_Libname (MyFile = );

%if %sysfunc(libname('MYMDB', 'ACCESS', "&amp;amp;myfile", 'readonly')) %then
%put %sysfunc(sysmsg());

%mend Assign_Libname;

%Assign_Libname (MyFile = %str(D:\MyDir\MyFile.MDB)); &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Dec 2015 22:25:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/LIBNAME-error-trapping/m-p/238183#M55414</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2015-12-07T22:25:31Z</dc:date>
    </item>
    <item>
      <title>Re: LIBNAME error trapping?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/LIBNAME-error-trapping/m-p/238184#M55415</link>
      <description>&lt;P&gt;Do it in a data step instead of using macro code. Especially if you want to create metadata.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data data_sources;
  infile cards truncover;
  length engine libref $8 rc 8 path msg $200 ;
  input engine $ path $200. ;
  libref='L'||put(_n_,Z7.);
  rc=libname(libref,path,engine,'access=readonly');
  if rc then msg=sysmsg();
  else msg='SUCCESS';
  output;
  rc=libname(libref,' ');
cards;
base c:\downloads
base c:\notfound
xlsx c:\downloads\DSPI.xlsx
;;;;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;results:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;287   data _null_; set ; put (_all_) (=/); run;
&lt;BR /&gt;engine=base
libref=L0000001
rc=0
path=c:\downloads
msg=SUCCESS

engine=base
libref=L0000002
rc=-70008
path=c:\notfound
msg=NOTE: Library L0000002 does not exist.

engine=xlsx
libref=L0000003
rc=0
path=c:\downloads\DSPI.xlsx
msg=SUCCESS

NOTE: There were 3 observations read from the data set WORK.DATA_SOURCES.
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Dec 2015 22:44:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/LIBNAME-error-trapping/m-p/238184#M55415</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2015-12-07T22:44:53Z</dc:date>
    </item>
  </channel>
</rss>

