<?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 How to conditionally assign a library on a unix server in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-conditionally-assign-a-library-on-a-unix-server/m-p/964547#M45908</link>
    <description>&lt;P&gt;I have tried this script and it is not working.&amp;nbsp; It always want to declare the libname even if it already exits&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro test;
*libname data clear;
data test;
keep response;
response =libref("data");
%if response ne 0 %then 
%do;
	%PUT "Creating the libname data";
	LIBNAME data "&amp;amp;path1./data/";
%end;
run;

%mend test;
%test;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;How to solve that issue&lt;/P&gt;</description>
    <pubDate>Thu, 17 Apr 2025 19:48:44 GMT</pubDate>
    <dc:creator>alepage</dc:creator>
    <dc:date>2025-04-17T19:48:44Z</dc:date>
    <item>
      <title>How to conditionally assign a library on a unix server</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-conditionally-assign-a-library-on-a-unix-server/m-p/964547#M45908</link>
      <description>&lt;P&gt;I have tried this script and it is not working.&amp;nbsp; It always want to declare the libname even if it already exits&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro test;
*libname data clear;
data test;
keep response;
response =libref("data");
%if response ne 0 %then 
%do;
	%PUT "Creating the libname data";
	LIBNAME data "&amp;amp;path1./data/";
%end;
run;

%mend test;
%test;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;How to solve that issue&lt;/P&gt;</description>
      <pubDate>Thu, 17 Apr 2025 19:48:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-conditionally-assign-a-library-on-a-unix-server/m-p/964547#M45908</guid>
      <dc:creator>alepage</dc:creator>
      <dc:date>2025-04-17T19:48:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to conditionally assign a library on a unix server</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-conditionally-assign-a-library-on-a-unix-server/m-p/964551#M45909</link>
      <description>&lt;P&gt;&lt;FONT face="courier new,courier"&gt;%IF&lt;/FONT&gt; cannot access values of a data step variable such as &lt;FONT face="courier new,courier"&gt;response&lt;/FONT&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Maybe like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* UNTESTED CODE */

%let response = %sysfunc(libref(data));
%put &amp;amp;=response;

%if &amp;amp;response ne 0 %then %do;
    %PUT Creating the libname data;
    options dlcreatedir;
    LIBNAME data "&amp;amp;path1/data";
%end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Which brings up the question ... why bother testing? If DATA is a currently assigned libname, or if it NOT a currently assigned libname, the LIBNAME statement should execute without problems. No conditional branching is needed here.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is this related to your &lt;A href="https://communities.sas.com/t5/SAS-Enterprise-Guide/Unable-to-clear-or-re-assign-the-library-DATA-because-it-is/m-p/964452#M45898" target="_self"&gt;earlier thread&lt;/A&gt;? If so, the problem I think you are having is that you never identified the cause of this error. And so that will continue to be a problem until you identify the cause and fix it. Marking the answer correct doesn't mean you have found the cause.&lt;/P&gt;</description>
      <pubDate>Thu, 17 Apr 2025 21:06:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-conditionally-assign-a-library-on-a-unix-server/m-p/964551#M45909</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2025-04-17T21:06:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to conditionally assign a library on a unix server</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-conditionally-assign-a-library-on-a-unix-server/m-p/964552#M45910</link>
      <description>&lt;P&gt;The LIBREF() function verifies that a libref has been assigned.&amp;nbsp; If the libref is assigned, then it returns a 0; if not assigned then it returns a nonzero value.&lt;BR /&gt;&lt;BR /&gt;From your code, it seems to me that you are wanting to check to see if a LIBREF has been assigned, and if not then assign it.&amp;nbsp; You might try something like this:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;%macro testlibref (libref, path) ;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp;%local libref path rc ;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp;%if %sysfunc(libref(&amp;amp;libref)) %then %let rc = %sysfunc(libname(&amp;amp;libref, &amp;amp;path) ;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;%mend testlibraf ;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;/* UNIX example */&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;%testlibref (MYLIB, /my/test/library) ;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;/*Windows example */&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;%testlibref (MYLIB, c:\my\test\library) ;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Or you may&amp;nbsp; prefer a data step to accomplish this, it can provide a little stronger control of quotes and things:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;/* UNIX example */&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;data _null_ ;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp;if libref('/my/test/library') then call execute ("libname MYLIB '/my/test/library' ;") ;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;run ;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;/* Windows&amp;nbsp; example */&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;data _null_ ;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp;if libref(''c:\my\test\library') then call execute ("libname MYLIB 'c:\my\test\library' ;") ;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;run ;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Apr 2025 21:28:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-conditionally-assign-a-library-on-a-unix-server/m-p/964552#M45910</guid>
      <dc:creator>PaulMcDonald-AZ</dc:creator>
      <dc:date>2025-04-17T21:28:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to conditionally assign a library on a unix server</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-conditionally-assign-a-library-on-a-unix-server/m-p/964564#M45911</link>
      <description>&lt;P&gt;You could use libname() funtion in data step to get job done.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;

data _null_;
response =libref("data");
put response=;
if response ne 0 then rc=libname('data','c:\temp');
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 18 Apr 2025 01:49:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-conditionally-assign-a-library-on-a-unix-server/m-p/964564#M45911</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2025-04-18T01:49:12Z</dc:date>
    </item>
  </channel>
</rss>

