<?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 Library assignment check in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Library-assignment-check/m-p/776081#M246750</link>
    <description>&lt;P&gt;I am checking if a Library is assigned or not as per the code (at the end of this message)&lt;/P&gt;&lt;P&gt;As you can see, there are no statements assigning any libraries, but still when I check if the library was assigned, it shows assigned.&lt;/P&gt;&lt;P&gt;In the job I haven't assigned any of the libraries (RAMSN, CDC3, CDC4, CDC5, PUB, CLBP2), I deliberately removed the assignment statements to see if the logic works or not, it's not working. Not sure what's wrong.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please check the log file attached for the same - "Libcheck-log.txt". I removed my ID details and replaced it with xxxx in the log, rest all is intact as it was generated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;SAS JOB -&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;%include '/home/xxxx/temp/cred.sas';&lt;BR /&gt;%include '/home/xxxx/temp/ldap.sas';&lt;BR /&gt;Libname mylib '/home/xxxx/temp';&lt;/P&gt;&lt;P&gt;%Global RAMSNEXISTS CDC3EXISTS CDC4EXISTS CDC5EXISTS PUBEXISTS CLBP2EXISTS;&lt;BR /&gt;Options source source2 notes symbolgen mlogic mprint ;&lt;/P&gt;&lt;P&gt;%Macro RamsCheck(RAMSN);&lt;BR /&gt;%Let RAMSNEXISTS=0;&lt;BR /&gt;%IF %SYSFUNC(LIBREF(RAMSN))=0 %THEN %Let RAMSNEXISTS=1;&lt;BR /&gt;%Mend;&lt;BR /&gt;%Macro CDC3Check(CDC3);&lt;BR /&gt;%Let CDC3EXISTS=0;&lt;BR /&gt;%IF %SYSFUNC(LIBREF(CDC3))=0 %THEN %Let CDC3EXISTS=1;&lt;BR /&gt;%Mend;&lt;BR /&gt;%Macro CDC4Check(CDC4);&lt;BR /&gt;%Let CDC4EXISTS=0;&lt;BR /&gt;%IF %SYSFUNC(LIBREF(CDC4))=0 %THEN %Let CDC4EXISTS=1;&lt;BR /&gt;%Mend;&lt;BR /&gt;%Macro CDC5Check(CDC5);&lt;BR /&gt;%Let CDC5EXISTS=0;&lt;BR /&gt;%IF %SYSFUNC(LIBREF(CDC5))=0 %THEN %Let CDC5EXISTS=1;&lt;BR /&gt;%Mend;&lt;BR /&gt;%Macro PUBCheck(PUB);&lt;BR /&gt;%Let PUBEXISTS=0;&lt;BR /&gt;%IF %SYSFUNC(LIBREF(PUB))=0 %THEN %Let PUBEXISTS=1;&lt;BR /&gt;%Mend;&lt;BR /&gt;%Macro CLBP2Check(CLBP2);&lt;BR /&gt;%Let CLBP2EXISTS=0;&lt;BR /&gt;%IF %SYSFUNC(LIBREF(CLBP2))=0 %THEN %Let CLBP2EXISTS=1;&lt;BR /&gt;%Mend;&lt;/P&gt;&lt;P&gt;LIBNAME RAMSN CLEAR;&lt;BR /&gt;%RamsCheck(RAMSN);&lt;BR /&gt;LIBNAME CDC3 CLEAR;&lt;BR /&gt;%CDC3Check(CDC3);&lt;BR /&gt;LIBNAME CDC4 CLEAR;&lt;BR /&gt;%CDC4Check(CDC4);&lt;BR /&gt;LIBNAME CDC5 CLEAR;&lt;BR /&gt;%CDC5Check(CDC5);&lt;BR /&gt;LIBNAME PUB CLEAR;&lt;BR /&gt;%PUBCheck(PUB);&lt;BR /&gt;LIBNAME CLBP2 CLEAR;&lt;BR /&gt;%CLBP2Check(CLBP2);&lt;/P&gt;&lt;P&gt;%Put &amp;amp;RAMSNEXISTS.;&lt;BR /&gt;%Put VALUE IS %SYSFUNC(LIBREF(RAMSN));&lt;BR /&gt;%Put &amp;amp;CDC3EXISTS.;&lt;BR /&gt;%Put VALUE IS %SYSFUNC(LIBREF(CDC3));&lt;BR /&gt;%Put &amp;amp;CDC4EXISTS.;&lt;BR /&gt;%Put VALUE IS %SYSFUNC(LIBREF(CDC4));&lt;BR /&gt;%Put &amp;amp;CDC5EXISTS.;&lt;BR /&gt;%Put VALUE IS %SYSFUNC(LIBREF(CDC5));&lt;BR /&gt;%Put &amp;amp;PUBEXISTS.;&lt;BR /&gt;%Put VALUE IS %SYSFUNC(LIBREF(PUB));&lt;BR /&gt;%Put &amp;amp;CLBP2EXISTS.;&lt;BR /&gt;%Put VALUE IS %SYSFUNC(LIBREF(CLBP2));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 24 Oct 2021 13:45:50 GMT</pubDate>
    <dc:creator>pradeep_kadasi</dc:creator>
    <dc:date>2021-10-24T13:45:50Z</dc:date>
    <item>
      <title>Library assignment check</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Library-assignment-check/m-p/776081#M246750</link>
      <description>&lt;P&gt;I am checking if a Library is assigned or not as per the code (at the end of this message)&lt;/P&gt;&lt;P&gt;As you can see, there are no statements assigning any libraries, but still when I check if the library was assigned, it shows assigned.&lt;/P&gt;&lt;P&gt;In the job I haven't assigned any of the libraries (RAMSN, CDC3, CDC4, CDC5, PUB, CLBP2), I deliberately removed the assignment statements to see if the logic works or not, it's not working. Not sure what's wrong.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please check the log file attached for the same - "Libcheck-log.txt". I removed my ID details and replaced it with xxxx in the log, rest all is intact as it was generated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;SAS JOB -&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;%include '/home/xxxx/temp/cred.sas';&lt;BR /&gt;%include '/home/xxxx/temp/ldap.sas';&lt;BR /&gt;Libname mylib '/home/xxxx/temp';&lt;/P&gt;&lt;P&gt;%Global RAMSNEXISTS CDC3EXISTS CDC4EXISTS CDC5EXISTS PUBEXISTS CLBP2EXISTS;&lt;BR /&gt;Options source source2 notes symbolgen mlogic mprint ;&lt;/P&gt;&lt;P&gt;%Macro RamsCheck(RAMSN);&lt;BR /&gt;%Let RAMSNEXISTS=0;&lt;BR /&gt;%IF %SYSFUNC(LIBREF(RAMSN))=0 %THEN %Let RAMSNEXISTS=1;&lt;BR /&gt;%Mend;&lt;BR /&gt;%Macro CDC3Check(CDC3);&lt;BR /&gt;%Let CDC3EXISTS=0;&lt;BR /&gt;%IF %SYSFUNC(LIBREF(CDC3))=0 %THEN %Let CDC3EXISTS=1;&lt;BR /&gt;%Mend;&lt;BR /&gt;%Macro CDC4Check(CDC4);&lt;BR /&gt;%Let CDC4EXISTS=0;&lt;BR /&gt;%IF %SYSFUNC(LIBREF(CDC4))=0 %THEN %Let CDC4EXISTS=1;&lt;BR /&gt;%Mend;&lt;BR /&gt;%Macro CDC5Check(CDC5);&lt;BR /&gt;%Let CDC5EXISTS=0;&lt;BR /&gt;%IF %SYSFUNC(LIBREF(CDC5))=0 %THEN %Let CDC5EXISTS=1;&lt;BR /&gt;%Mend;&lt;BR /&gt;%Macro PUBCheck(PUB);&lt;BR /&gt;%Let PUBEXISTS=0;&lt;BR /&gt;%IF %SYSFUNC(LIBREF(PUB))=0 %THEN %Let PUBEXISTS=1;&lt;BR /&gt;%Mend;&lt;BR /&gt;%Macro CLBP2Check(CLBP2);&lt;BR /&gt;%Let CLBP2EXISTS=0;&lt;BR /&gt;%IF %SYSFUNC(LIBREF(CLBP2))=0 %THEN %Let CLBP2EXISTS=1;&lt;BR /&gt;%Mend;&lt;/P&gt;&lt;P&gt;LIBNAME RAMSN CLEAR;&lt;BR /&gt;%RamsCheck(RAMSN);&lt;BR /&gt;LIBNAME CDC3 CLEAR;&lt;BR /&gt;%CDC3Check(CDC3);&lt;BR /&gt;LIBNAME CDC4 CLEAR;&lt;BR /&gt;%CDC4Check(CDC4);&lt;BR /&gt;LIBNAME CDC5 CLEAR;&lt;BR /&gt;%CDC5Check(CDC5);&lt;BR /&gt;LIBNAME PUB CLEAR;&lt;BR /&gt;%PUBCheck(PUB);&lt;BR /&gt;LIBNAME CLBP2 CLEAR;&lt;BR /&gt;%CLBP2Check(CLBP2);&lt;/P&gt;&lt;P&gt;%Put &amp;amp;RAMSNEXISTS.;&lt;BR /&gt;%Put VALUE IS %SYSFUNC(LIBREF(RAMSN));&lt;BR /&gt;%Put &amp;amp;CDC3EXISTS.;&lt;BR /&gt;%Put VALUE IS %SYSFUNC(LIBREF(CDC3));&lt;BR /&gt;%Put &amp;amp;CDC4EXISTS.;&lt;BR /&gt;%Put VALUE IS %SYSFUNC(LIBREF(CDC4));&lt;BR /&gt;%Put &amp;amp;CDC5EXISTS.;&lt;BR /&gt;%Put VALUE IS %SYSFUNC(LIBREF(CDC5));&lt;BR /&gt;%Put &amp;amp;PUBEXISTS.;&lt;BR /&gt;%Put VALUE IS %SYSFUNC(LIBREF(PUB));&lt;BR /&gt;%Put &amp;amp;CLBP2EXISTS.;&lt;BR /&gt;%Put VALUE IS %SYSFUNC(LIBREF(CLBP2));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 24 Oct 2021 13:45:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Library-assignment-check/m-p/776081#M246750</guid>
      <dc:creator>pradeep_kadasi</dc:creator>
      <dc:date>2021-10-24T13:45:50Z</dc:date>
    </item>
    <item>
      <title>Re: Library assignment check</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Library-assignment-check/m-p/776090#M246751</link>
      <description>&lt;P&gt;Query DICTIONARY.LIBNAMES (SQL procedure) or SASHELP.VLIBNAM (data step, other procedures) instead when you need to check for a number of libraries.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You create macro variables inside your macros without declaring them global (%GLOBAL statement), so they are defined in the local symbol table and vanish as soon as the macro stops executing.&lt;/P&gt;</description>
      <pubDate>Sun, 24 Oct 2021 16:33:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Library-assignment-check/m-p/776090#M246751</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-10-24T16:33:53Z</dc:date>
    </item>
    <item>
      <title>Re: Library assignment check</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Library-assignment-check/m-p/776094#M246752</link>
      <description>&lt;P&gt;Since in this macro&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro RamsCheck(RAMSN);
%let RAMSNEXISTS=0;
%if %SYSFUNC(LIBREF(RAMSN))=0 %then %Let RAMSNEXISTS=1;
%mend;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;you haven't et RAMSNEXISTS to either LOCAL or GLOBAL it will default to local if there is not already a macro variable with that name.&amp;nbsp; So to use the macro make sure to create the target macro variable before running the macro.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;LIBNAME RAMSN CLEAR;
%let RAMSNEXISTS=Before macro call;
%RamsCheck(RAMSN);
%put &amp;amp;=RAMSNEXISTS;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It might be simpler to create a single macro to do the test.&amp;nbsp; Similar to this macro for using the FILEREF() function.&amp;nbsp;&lt;A href="https://github.com/sasutils/macros/blob/master/fileref.sas" target="_blank"&gt;https://github.com/sasutils/macros/blob/master/fileref.sas&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then your logic can instead be:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let RAMSNEXISTS=%libref(RAMSN);
%let CDC3EXISTS=%libref(CDC3);
...&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;What result do you want when the libref is defined, but it is pointing at something that does not exist?&lt;/P&gt;
&lt;PRE&gt;7     libname xxx 'c:\downloads';
NOTE: Libref XXX was successfully assigned as follows:
      Engine:        V9
      Physical Name: c:\downloads
8     %put %sysfunc(libref(xxx));
0
9     libname xxx clear;
NOTE: Libref XXX has been deassigned.
10    %put %sysfunc(libref(xxx));
70006
11    libname xxx 'c:\no such\directory';
NOTE: Library XXX does not exist.
12    %put %sysfunc(libref(xxx));
-70008
&lt;/PRE&gt;</description>
      <pubDate>Sun, 24 Oct 2021 17:55:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Library-assignment-check/m-p/776094#M246752</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-10-24T17:55:56Z</dc:date>
    </item>
  </channel>
</rss>

