<?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: skip a data step if lib ref not found in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/skip-a-data-step-if-lib-ref-not-found/m-p/679847#M205332</link>
    <description>&lt;P&gt;You can use the LIBREF function in a macro variable as in&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let abc=%sysfunc(libref(test));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If macro variable &amp;amp;ABC is 0 then the library exists, otherwise it does not exist.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can then create a branch around this data step inside a macro, or if you have SAS V.94M5 or later, you can use it in a simple %IF - %THEN block, even outside a macro.&lt;/P&gt;</description>
    <pubDate>Thu, 27 Aug 2020 17:53:50 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2020-08-27T17:53:50Z</dc:date>
    <item>
      <title>skip a data step if lib ref not found</title>
      <link>https://communities.sas.com/t5/SAS-Programming/skip-a-data-step-if-lib-ref-not-found/m-p/679823#M205326</link>
      <description>&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;FONT color="#0000ff"&gt;prior code is OK.&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;42 libname TEST '/sas/sasmain/mydept/Test Report';&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;NOTE: Library TEST does not exist.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;43 run;&lt;/P&gt;&lt;P&gt;44&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;FONT color="#0000ff"&gt;I'd like to skip the next datastep&amp;nbsp; if the TEST library is not found,&amp;nbsp; or perhaps use a macro variable for the phrase "successfully",&amp;nbsp; depending on the return code of the libname statement (above).&amp;nbsp; Is there a return code&amp;nbsp;to test ?&amp;nbsp; &amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#000080"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt; &lt;FONT face="Courier New" size="3" color="#0000ff"&gt;_null_&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;file&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; outbox&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;cc&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;=&lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#800080"&gt;"bossman.last@compny.com"&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;subject=&lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#800080"&gt;"Report process completed&amp;nbsp;- &amp;amp;sysuserid "&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; ;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;put&lt;/FONT&gt; &lt;FONT face="Courier New" size="3" color="#800080"&gt;" "&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;put&lt;/FONT&gt; &lt;FONT face="Courier New" size="3" color="#800080"&gt;"&amp;amp;sysdate&amp;nbsp;The Test/Report process &lt;EM&gt;successfully&lt;/EM&gt; completed by: &amp;amp;sysuserid "&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;put&lt;/FONT&gt; &lt;FONT face="Courier New" size="3" color="#800080"&gt;" "&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; ;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#000080"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Aug 2020 17:34:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/skip-a-data-step-if-lib-ref-not-found/m-p/679823#M205326</guid>
      <dc:creator>GailVanCourt</dc:creator>
      <dc:date>2020-08-27T17:34:20Z</dc:date>
    </item>
    <item>
      <title>Re: skip a data step if lib ref not found</title>
      <link>https://communities.sas.com/t5/SAS-Programming/skip-a-data-step-if-lib-ref-not-found/m-p/679847#M205332</link>
      <description>&lt;P&gt;You can use the LIBREF function in a macro variable as in&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let abc=%sysfunc(libref(test));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If macro variable &amp;amp;ABC is 0 then the library exists, otherwise it does not exist.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can then create a branch around this data step inside a macro, or if you have SAS V.94M5 or later, you can use it in a simple %IF - %THEN block, even outside a macro.&lt;/P&gt;</description>
      <pubDate>Thu, 27 Aug 2020 17:53:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/skip-a-data-step-if-lib-ref-not-found/m-p/679847#M205332</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-08-27T17:53:50Z</dc:date>
    </item>
    <item>
      <title>Re: skip a data step if lib ref not found</title>
      <link>https://communities.sas.com/t5/SAS-Programming/skip-a-data-step-if-lib-ref-not-found/m-p/679854#M205338</link>
      <description>&lt;P&gt;To skip a step need a macro programing:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro chklib(path);
   %if %sysfunc(fileexist(&amp;amp;path)) %then %do;
        libname TEST "&amp;amp;path";
		data _null_;
		file outbox
		cc="bossman.last@compny.com"
		subject="Report process completed - &amp;amp;sysuserid " ;
		put " ";
		put "&amp;amp;sysdate The Test/Report process successfully completed by: &amp;amp;sysuserid ";
		put " " ;
		run;
	%end;
%mend chklib;
%chklib(/sas/sasmain/mydept/Test Report);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 27 Aug 2020 18:01:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/skip-a-data-step-if-lib-ref-not-found/m-p/679854#M205338</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2020-08-27T18:01:32Z</dc:date>
    </item>
    <item>
      <title>Re: skip a data step if lib ref not found</title>
      <link>https://communities.sas.com/t5/SAS-Programming/skip-a-data-step-if-lib-ref-not-found/m-p/679896#M205364</link>
      <description>&lt;P&gt;With all due respect,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/88384"&gt;@Shmuel&lt;/a&gt;&amp;nbsp;, I think your very close but off by a teensy little detail. The question was if the libref exists, not whether or not the folder exists. The folder can exist but libref not assigned, and I would think the original poster would want that to fail, at least as far as I understand the question. So the LIBREF function is needed, not FILEEXIST.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Aug 2020 20:20:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/skip-a-data-step-if-lib-ref-not-found/m-p/679896#M205364</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-08-27T20:20:15Z</dc:date>
    </item>
    <item>
      <title>Re: skip a data step if lib ref not found</title>
      <link>https://communities.sas.com/t5/SAS-Programming/skip-a-data-step-if-lib-ref-not-found/m-p/679920#M205372</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;, I could have a misunderstanding of the query.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/89558"&gt;@GailVanCourt&lt;/a&gt;&amp;nbsp;asked for&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;             prior code is OK. 
42 libname TEST '/sas/sasmain/mydept/Test Report';
NOTE: Library TEST does not exist.
43 run;
44
         I'd like to skip the next datastep  if the TEST library is not found, &lt;/PRE&gt;
&lt;P&gt;I can't regenerate such NOTE but could think of two different issues:&lt;/P&gt;
&lt;P&gt;1) path does not exist&lt;/P&gt;
&lt;P&gt;2) libref was not assigned&lt;/P&gt;
&lt;P&gt;In case 1 I would expect an ERROR message, not a NOTE.&lt;/P&gt;
&lt;P&gt;So my answer&amp;nbsp; focused on the requirement - how to check and skip a datastep.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;- can you explain in what situation, assignment of a libref creates the &lt;STRONG&gt;NOTE: Library &amp;lt;name&amp;gt; does not exist&lt;/STRONG&gt;, as shown above?&lt;/P&gt;</description>
      <pubDate>Thu, 27 Aug 2020 23:47:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/skip-a-data-step-if-lib-ref-not-found/m-p/679920#M205372</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2020-08-27T23:47:45Z</dc:date>
    </item>
    <item>
      <title>Re: skip a data step if lib ref not found</title>
      <link>https://communities.sas.com/t5/SAS-Programming/skip-a-data-step-if-lib-ref-not-found/m-p/679956#M205398</link>
      <description>&lt;P&gt;Finally I have regenerated the issue as shown in next log:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;73         libname test "/folders/myfolders/none";
 NOTE: Library TEST does not exist.
 74         
 75         %let abc=%sysfunc(libref(test));
 76         %put ABC=&amp;amp;abc;
 ABC=-70008
 77         
 78         %macro chklib(path);
 79            %if not %sysfunc(fileexist(&amp;amp;path))
 80            %then %put NOT EXIST;
 81            %else %put PATH EXISTS;
 82         %mend;
 83         %chklib(/folders/myfolders/flat);
 PATH EXISTS
 84         %chklib(/folders/myfolders/none);
 NOT EXIST&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 28 Aug 2020 05:48:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/skip-a-data-step-if-lib-ref-not-found/m-p/679956#M205398</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2020-08-28T05:48:35Z</dc:date>
    </item>
    <item>
      <title>Re: skip a data step if lib ref not found</title>
      <link>https://communities.sas.com/t5/SAS-Programming/skip-a-data-step-if-lib-ref-not-found/m-p/679960#M205402</link>
      <description>&lt;P&gt;Here is some code that illustrates a few things about the LIBNAME statement, the LIBREF function, and how SAS keeps certain things in the background:&lt;/P&gt;
&lt;P&gt;Before the code is run, a subdirectory xxx exists in /folders/myfolders, but not a subdirectory yyy.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname test1 '/folders/myfolders/xxx';
libname test2 '/folders/myfolders/yyy';

%macro chklib(lr);
   %if not %sysfunc(libref(&amp;amp;lr))
   %then %put EXIST;
   %else %put not EXISTS;
%mend;

%chklib(test1)
%chklib(test2)

%put %sysfunc(dcreate(yyy,/folders/myfolders));

%chklib(test2);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Log:&lt;/P&gt;
&lt;PRE&gt; 73         libname test1 '/folders/myfolders/xxx';
 NOTE: Libref TEST1 was successfully assigned as follows: 
       Engine:        V9 
       Physical Name: /folders/myfolders/xxx
 74         libname test2 '/folders/myfolders/yyy';
 NOTE: Bibliothek TEST2 existiert nicht.
 75         
 76         %macro chklib(lr);
 77            %if not %sysfunc(libref(&amp;amp;lr))
 78            %then %put EXIST;
 79            %else %put not EXISTS;
 80         %mend;
 81         
 82         %chklib(test1)
 EXIST
 83         %chklib(test2)
 not EXISTS
 84         
 85         %put %sysfunc(dcreate(yyy,/folders/myfolders));
 /folders/myfolders/yyy
 86         
 87         %chklib(test2);
 EXIST
&lt;/PRE&gt;
&lt;P&gt;So, although the library can't be assigned correctly (which is also correctly reported by the LIBREF function, which &amp;nbsp;returns a 0 if the libref exists, non-zero otherwise), the definition attempt is kept, and when the physical path is created, the LIBREF function reports the libref as defined, although no new LIBNAME statement was executed.&lt;/P&gt;</description>
      <pubDate>Fri, 28 Aug 2020 06:28:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/skip-a-data-step-if-lib-ref-not-found/m-p/679960#M205402</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-08-28T06:28:18Z</dc:date>
    </item>
    <item>
      <title>Re: skip a data step if lib ref not found</title>
      <link>https://communities.sas.com/t5/SAS-Programming/skip-a-data-step-if-lib-ref-not-found/m-p/680007#M205423</link>
      <description>I've been experimenting with all the replies. ALL are great, and worked. Keeping it simple, with a few comments for understanding. Thank you, Gail</description>
      <pubDate>Fri, 28 Aug 2020 13:01:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/skip-a-data-step-if-lib-ref-not-found/m-p/680007#M205423</guid>
      <dc:creator>GailVanCourt</dc:creator>
      <dc:date>2020-08-28T13:01:53Z</dc:date>
    </item>
    <item>
      <title>Re: skip a data step if lib ref not found</title>
      <link>https://communities.sas.com/t5/SAS-Programming/skip-a-data-step-if-lib-ref-not-found/m-p/680012#M205425</link>
      <description>&lt;P&gt;Thank You.&amp;nbsp;&amp;nbsp; I was pleasantly surprised by all the responses.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Aug 2020 13:11:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/skip-a-data-step-if-lib-ref-not-found/m-p/680012#M205425</guid>
      <dc:creator>GailVanCourt</dc:creator>
      <dc:date>2020-08-28T13:11:50Z</dc:date>
    </item>
    <item>
      <title>Re: skip a data step if lib ref not found</title>
      <link>https://communities.sas.com/t5/SAS-Programming/skip-a-data-step-if-lib-ref-not-found/m-p/680039#M205434</link>
      <description>&lt;P&gt;The result of the LIBREF() function is &lt;STRONG&gt;tri-level&lt;/STRONG&gt;, not binary.&lt;/P&gt;
&lt;P&gt;0 means libref was defined and file/directory was found.&lt;/P&gt;
&lt;P&gt;negative means libref was defined but file/directory was not found.&lt;/P&gt;
&lt;P&gt;positive means libref does not exist.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;72    libname test1 'c:\downloads\';
NOTE: Libref TEST1 was successfully assigned as follows:
      Engine:        V9
      Physical Name: c:\downloads
73    libname test2 'c:\no such directory\';
NOTE: Library TEST2 does not exist.
74
75    %put TEST1=%sysfunc(libref(TEST1));
TEST1=0
76    %put TEST2=%sysfunc(libref(TEST2));
TEST2=-70008
77    %put TEST3=%sysfunc(libref(TEST3));
TEST3=70006&lt;/PRE&gt;</description>
      <pubDate>Fri, 28 Aug 2020 14:57:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/skip-a-data-step-if-lib-ref-not-found/m-p/680039#M205434</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-08-28T14:57:24Z</dc:date>
    </item>
    <item>
      <title>Re: skip a data step if lib ref not found</title>
      <link>https://communities.sas.com/t5/SAS-Programming/skip-a-data-step-if-lib-ref-not-found/m-p/680055#M205444</link>
      <description>&lt;P&gt;Thank you again.&amp;nbsp; I was wondering about the ABC=-70008, in Shmuels' earlier post.&amp;nbsp;&amp;nbsp;&lt;BR /&gt;Keeping it (as) Simple (as possible) &amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Aug 2020 16:28:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/skip-a-data-step-if-lib-ref-not-found/m-p/680055#M205444</guid>
      <dc:creator>GailVanCourt</dc:creator>
      <dc:date>2020-08-28T16:28:10Z</dc:date>
    </item>
  </channel>
</rss>

