<?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: Changing project's behavior at runtime in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Changing-project-s-behavior-at-runtime/m-p/889191#M43458</link>
    <description>&lt;P&gt;The reason why I'm using a global, instead of a local value, is to be able to test it, if I need, into other project steps without the need to re-call the testing macro (of course it can be done, if one needs or have doubts the library is still assigned, at that further point).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;About&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;code (and aside of my little modification), as far as I tested it, it worked very well, as well as I'm replacing my original one (the one where I had the problem which made me to open this thread) with his one.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In my previous tests, with &lt;STRONG&gt;my&lt;/STRONG&gt; code, I was seeing that, even when the library have been assigned by using&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname &amp;amp;library_name. META LIBRARY="&amp;amp;library_name." metauser=&amp;amp;_METAUSER.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;when I re-tested it a little later, the project gave the error like it wasn't assigned. But, when I gone to see the library interactively, right-clicking on it, the contextual menu gave me the &lt;EM&gt;&lt;STRONG&gt;un&lt;/STRONG&gt;assign&lt;/EM&gt; item, which seems not congruent with the "library not assigned" error my program received.&lt;/P&gt;
&lt;P&gt;That's why I thought to use proc metalib&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc metalib;
	omr (library="&amp;amp;library_name.");
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;as, even when it fails ('cause of my auth lack), it seems syncing metadata: result is the next test works&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc contents data=&amp;amp;lib..&amp;amp;tab.;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;'s code solved the problem at the root, it seems as, after the&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname &amp;amp;lib. meta liburi="SASLibrary?@libref='&amp;amp;lib.'" metaout=data;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;engaged if &amp;amp;libexist is 0 only, further tests correctly access the library, all the solution into a single macro, also.&lt;/P&gt;
&lt;P&gt;I could then figure how to modify it, to test multiple libraries but, for a single one, it's working already.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;About the "assertion" part: it could be more correct to have &lt;STRONG&gt;&lt;EM&gt;another test&lt;/EM&gt;&lt;/STRONG&gt;, after the above libname... assignment, so to be sure the library is assigned, after that call (I know I'm assuming it is, right now) to end with librassigned = 1 to one side or the error message (plus libassigned = 0) to the other, you're right on that.&lt;/P&gt;</description>
    <pubDate>Mon, 14 Aug 2023 13:58:15 GMT</pubDate>
    <dc:creator>lc_isp</dc:creator>
    <dc:date>2023-08-14T13:58:15Z</dc:date>
    <item>
      <title>Changing project's behavior at runtime</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Changing-project-s-behavior-at-runtime/m-p/888136#M43408</link>
      <description>&lt;P&gt;&amp;nbsp; &amp;nbsp; Hi all,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm working with a SAS EG project which &lt;STRONG&gt;needs&lt;/STRONG&gt; to "&lt;EM&gt;continue running in case of errors&lt;/EM&gt;": to configure that (non-default) behavior there is a menu choice (Properties &amp;gt; Project properties &amp;gt; Code submission &amp;gt; Action to take on errors ...: Continue execution).&lt;/P&gt;
&lt;P&gt;Configuring the project this way, my &lt;STRONG&gt;first&lt;/STRONG&gt; step makes the project to solve a problem I'm having with a library so that's ok.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the &lt;STRONG&gt;following&lt;/STRONG&gt; steps tho, I would like to be able to &lt;EM&gt;revert project's behavior&lt;/EM&gt; to its default (so to stop, if it gets an error): I was wondering if there was any way, e.g. a system variable one can (re)set at runtime, for this to happen (e.g. %let &amp;amp;sysprjerrcodesubmit = "stop", or "0" or such), before to leave step 1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All that 'cause the project will be executed via &lt;STRONG&gt;batch&lt;/STRONG&gt; scheduler, so no human intervention will be there, to &lt;EM&gt;manually revert&lt;/EM&gt; the behavior (and other reasons too).&lt;/P&gt;</description>
      <pubDate>Mon, 07 Aug 2023 14:38:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Changing-project-s-behavior-at-runtime/m-p/888136#M43408</guid>
      <dc:creator>lc_isp</dc:creator>
      <dc:date>2023-08-07T14:38:54Z</dc:date>
    </item>
    <item>
      <title>Re: Changing project's behavior at runtime</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Changing-project-s-behavior-at-runtime/m-p/888282#M43412</link>
      <description>&lt;P&gt;Given this is a project property I highly doubt that you can change this on a task level. There might be coding options instead to have SAS continue to execute after an Error.&lt;/P&gt;
&lt;P&gt;If you say: Running in batch do you mean EG scheduling or "real" batch processing via some other scheduler?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If it's not just EG scheduling then many schedulers allow to define what should happen in case a task node fails - which can also be to continue running.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Ideally you're writing code that never throws errors or warnings. May-be share your code or at least describe in detail which error condition could occur where you still want to continue processing so we can propose some check logic instead that doesn't throw an Error (like fileexist or similar).&lt;/P&gt;</description>
      <pubDate>Tue, 08 Aug 2023 02:53:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Changing-project-s-behavior-at-runtime/m-p/888282#M43412</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-08-08T02:53:33Z</dc:date>
    </item>
    <item>
      <title>Re: Changing project's behavior at runtime</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Changing-project-s-behavior-at-runtime/m-p/888284#M43413</link>
      <description>&lt;P&gt;I haven't tested, but according to this paper by the great&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15089"&gt;@CaseySmith&lt;/a&gt;&amp;nbsp;&amp;nbsp;&lt;A href="https://support.sas.com/resources/papers/proceedings17/SAS0562-2017.pdf," target="_blank"&gt;https://support.sas.com/resources/papers/proceedings17/SAS0562-2017.pdf,&lt;/A&gt;&amp;nbsp;in addition to setting this option at the project-level you can set it for an individual item in your EG flow.&amp;nbsp; So sounds like you can leave the project configuration as the default (stop on error) and then change the option for the first item in the flow to "continue execution."&lt;/P&gt;</description>
      <pubDate>Tue, 08 Aug 2023 03:40:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Changing-project-s-behavior-at-runtime/m-p/888284#M43413</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2023-08-08T03:40:14Z</dc:date>
    </item>
    <item>
      <title>Re: Changing project's behavior at runtime</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Changing-project-s-behavior-at-runtime/m-p/888333#M43418</link>
      <description>&lt;P&gt;TYVM Quentin: your hint totally solved my problem!&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":thumbs_up:"&gt;👍&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;I did all the testing, creating errors on purpose, and the (single) tasks configured to "&lt;EM&gt;keep going&lt;/EM&gt;" left the process &lt;STRONG&gt;running through&lt;/STRONG&gt;, which is exactly what I needed as, sometimes, even errors are wanted/needed, to check some conditions or about other purposes: this way we avoid the whole project is stopped, if a (wanted) error happens.&lt;/P&gt;
&lt;P&gt;As I needed such behavior into a &lt;STRONG&gt;limited&lt;/STRONG&gt; part of my project only, all other tasks are &lt;EM&gt;still free to use the global setting&lt;/EM&gt; (so, to stop if the project falls in error, which is the wanted behavior).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;cheers!&lt;/P&gt;</description>
      <pubDate>Tue, 08 Aug 2023 12:27:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Changing-project-s-behavior-at-runtime/m-p/888333#M43418</guid>
      <dc:creator>lc_isp</dc:creator>
      <dc:date>2023-08-08T12:27:44Z</dc:date>
    </item>
    <item>
      <title>Re: Changing project's behavior at runtime</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Changing-project-s-behavior-at-runtime/m-p/888379#M43420</link>
      <description>&lt;P&gt;Hi Patrick, and thanks for your hints too.&lt;/P&gt;
&lt;P&gt;As for Quentin's hints, SAS EG nowadays have ways to decide, at &lt;STRONG&gt;task-level&lt;/STRONG&gt;, what to do when an error condition arises (this while still keeping the &lt;EM&gt;global setting&lt;/EM&gt; in action, which is good).&lt;/P&gt;
&lt;P&gt;I thought there was a way to "switch" such "&lt;EM&gt;global flag&lt;/EM&gt;" but it's ok to operate this way too (it's a setup, after all): both ways solve my problems.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;About the project and the reason why some parts are &lt;STRONG&gt;expected&lt;/STRONG&gt; to &lt;EM&gt;raise errors&lt;/EM&gt;: I believe we're having a "&lt;EM&gt;not properly configured&lt;/EM&gt;" library access, for which (and differently than other libraries we're accessing already) a library I'm accessing to automate some data-extraction results &lt;STRONG&gt;un&lt;/STRONG&gt;assigned when I open my project.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As far as I'm working interactively it's not a problem, as I can re-assign the library in a moment (and always succesfully) but, as my main work is to &lt;STRONG&gt;automate&lt;/STRONG&gt; processes, I was wondering what happened if the project was launched by SAS EG Scheduler (or even by SAS Management Console, which I've no access to, at the moment, but my hopes are toward it, for the future): whichever "&lt;EM&gt;scheduler&lt;/EM&gt;" will be involved, no human intervention is possible, if the task runs "by its own" (scheduler) at 1am everyday.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thus, I dug the net, to try solving such case (and ok, I &lt;U&gt;totally agree&lt;/U&gt; that the &lt;STRONG&gt;real&lt;/STRONG&gt; solution is to ask for a proper library access configuration... but, sometimes, such things are terribly hard/time consuming to obtain: an "alternative solution" could help anyway).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="20230808_SAS_libref_error_mgmt.jpg" style="width: 456px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/86527iC092B05C8CCB04C0/image-size/large?v=v2&amp;amp;px=999" role="button" title="20230808_SAS_libref_error_mgmt.jpg" alt="20230808_SAS_libref_error_mgmt.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So I put together a project step where the first task checks for the library assignment, if ok it sets a variable (&lt;EM&gt;&amp;amp;libassigned&lt;/EM&gt;) to 1, so to take profit of the conditional execution.&lt;/P&gt;
&lt;P&gt;If the next task gets that variable as &lt;STRONG&gt;0&lt;/STRONG&gt;, EG starts a (re)assignment task (and here starts the weird): I noticed that, &lt;EM&gt;even when the (re)assignment works&lt;/EM&gt;, the following tasks &lt;STRONG&gt;fails&lt;/STRONG&gt; anyway (with "library not assigned" error), like there was "something wrong" with metadata. Searching more, I solved the problem by using proc metalib, which I'm &lt;U&gt;&lt;STRONG&gt;not&lt;/STRONG&gt;&lt;/U&gt; authorized to but, even when it fails, it seems it &lt;EM&gt;successfully sync metadata&lt;/EM&gt;, so that the following steps works properly: that's why I need, in this project-step only, the execution to keep going even when a task (proc metalib) fails.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;By using Quentin's hints, configuring the "go on" behavior to a &lt;STRONG&gt;&lt;EM&gt;few tasks&lt;/EM&gt;&lt;/STRONG&gt;, I can leave the rest of the project "clean" (considering that behavior only) to my colleagues, which are used that the project&amp;nbsp; &lt;STRONG&gt;&lt;EM&gt;stops&lt;/EM&gt;&lt;/STRONG&gt; if errors arise.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;With time, I believe I'll manage to achieve a better/proper access setup to that library too but, for the moment, my "patch" is working.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best,&lt;/P&gt;</description>
      <pubDate>Tue, 08 Aug 2023 14:25:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Changing-project-s-behavior-at-runtime/m-p/888379#M43420</guid>
      <dc:creator>lc_isp</dc:creator>
      <dc:date>2023-08-08T14:25:02Z</dc:date>
    </item>
    <item>
      <title>Re: Changing project's behavior at runtime</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Changing-project-s-behavior-at-runtime/m-p/888478#M43427</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/267902"&gt;@lc_isp&lt;/a&gt;&amp;nbsp;So if I understand right then you've got a library in SAS metadata where you're not sure if it's pre-assigned or not. If so then you could first run a SQL query against dictionary.libnames to check if the expected libref exists.&lt;/P&gt;
&lt;P&gt;If the libref does not exist then you could assign it via a libname statement that uses the existing metadata library definition.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let libexist_flg=0;
proc sql;
  select count(*)=1 into :libexist_flg trimmed
  from dictionary.libnames
  where libname='MYLIB'
  ;
quit;

%if libexist_flg=0 %then
  %do;
    libname mylib meta SASLibrary?@libref='mylib' metaout=data;
  %end
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Aug 2023 22:02:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Changing-project-s-behavior-at-runtime/m-p/888478#M43427</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-08-08T22:02:11Z</dc:date>
    </item>
    <item>
      <title>Re: Changing project's behavior at runtime</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Changing-project-s-behavior-at-runtime/m-p/888612#M43433</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;I'm nearly sure, from SAS behavior, the library I'm accessing is not pre-assigned: sometimes I had no problems to "just access it" (e.g. running a program which read a table), but that's possibly 'cause I accessed it some hours before: 90% of the times I "just run a program" which tried accessing it, SAS gave me back an "ERROR: Libref &amp;lt;libname&amp;gt; is not assigned.".&lt;/P&gt;
&lt;P&gt;To have the access modified, it's probably "harder" (time consuming, with uncertain results) than implementing the check-and-retry mechanism you also depicted in your code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;About your code: I tried modifying it, to work with a parameter (&amp;amp;lib)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let libexist_flg=0;
%let lib=XYZ123;

proc sql;
  select count(*)=1 into :libexist_flg trimmed
  from dictionary.libnames
  where libname="&amp;amp;lib."
  ;
quit;

%if libexist_flg=0 %then
  %do;
    libname &amp;amp;lib. meta SASLibrary?@libref="&amp;amp;lib." metaout=data;
  %end&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;but SAS seems having a problem with the SASLibrary?@libref="&amp;amp;lib" part, and I still don't know SAS programming enough (zero courses) to see where the error is:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;44       !                          SASLibrary?@libref="&amp;amp;lib." metaout=data;
                                    __________  ______
                                    23          22
ERROR 23-7: Invalid value for the SASLIBRARY option.

ERROR 22-7: Invalid option name LIBREF.

44       ! SASLibrary?@libref="&amp;amp;lib." metaout=data;
                                              _
                                              23
ERROR 23-7: Invalid value for the ? option.&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I probably misunderstood your code about some parameter.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Aug 2023 16:48:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Changing-project-s-behavior-at-runtime/m-p/888612#M43433</guid>
      <dc:creator>lc_isp</dc:creator>
      <dc:date>2023-08-09T16:48:46Z</dc:date>
    </item>
    <item>
      <title>Re: Changing project's behavior at runtime</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Changing-project-s-behavior-at-runtime/m-p/888693#M43436</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/267902"&gt;@lc_isp&lt;/a&gt;&amp;nbsp; Below code works in my environment (tested).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro assign_lib(lib);
  %let lib=%upcase(&amp;amp;lib);

  %local libexist_flg;
  %let libexist_flg=0;
  proc sql noprint;
    select count(*)&amp;gt;1 into :libexist_flg trimmed
    from dictionary.libnames
    where libname=%upcase("&amp;amp;lib.")
    ;
  quit;
  %put &amp;amp;=libexist_flg;

  %if &amp;amp;libexist_flg=0 %then
    %do;
      libname &amp;amp;lib. meta liburi="SASLibrary?@libref='&amp;amp;lib.'" metaout=data;
    %end;
%mend;
%assign_lib(mylib);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In above code the macro call expects a library in SAS metadata defined with a libref &lt;EM&gt;mylib&lt;/EM&gt;.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Aug 2023 23:33:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Changing-project-s-behavior-at-runtime/m-p/888693#M43436</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-08-09T23:33:14Z</dc:date>
    </item>
    <item>
      <title>Re: Changing project's behavior at runtime</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Changing-project-s-behavior-at-runtime/m-p/888925#M43444</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;thanks again for the code and explanations (and your testing time).&lt;/P&gt;
&lt;P&gt;I changed the code a little, and tested it: it's &lt;EM&gt;&lt;STRONG&gt;working&lt;/STRONG&gt;&lt;/EM&gt;, and without the need of &lt;EM&gt;proc metalib / error management&lt;/EM&gt;. I'll use it more, in the project I'm working on, to see if it needs further changes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm showing the &lt;EM&gt;changes&lt;/EM&gt;, below, if someone likes to use them (last part, about &lt;EM&gt;&lt;STRONG&gt;proc contents&lt;/STRONG&gt;&lt;/EM&gt;, is optional, just to test libref have been really assigned and the library is &lt;EM&gt;available to use)&lt;/EM&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;OPTIONS mprint mprintnest mlogic mlogicnest symbolgen syntaxcheck autocorrect fullstimer source stimer threads;	/* DEBUG: _VERBOSE_ */
/*OPTIONS nonotes nomprint nomprintnest nomlogic nomlogicnest nosymbolgen nosyntaxcheck noautocorrect nofullstimer nosource nostimer threads;*/	/* INFO: SHORT */

%global libexist;
%global mylib;

%let mylib=gn777A;																/* lower-case chars are on purpose */

%macro assign_lib(lib);
	%let lib=%upcase(&amp;amp;lib);

	%put &amp;amp;=lib;

	/*%local libexist;*/
	%let libexist=0;
	proc sql noprint;
		select count(*)&amp;gt;1 into :libexist trimmed
		from dictionary.libnames
		where libname=%upcase("&amp;amp;lib.")
		;
	quit;
	%put &amp;amp;=libexist;

	%if &amp;amp;libexist=0 %then
		%do;
			libname &amp;amp;lib. meta liburi="SASLibrary?@libref='&amp;amp;lib.'" metaout=data;
		%end;
%mend;

%put &amp;amp;=mylib;

%assign_lib(&amp;amp;mylib.);

%put &amp;amp;=libexist;

/* just to check if libref was finally assigned */
%if &amp;amp;libexist. ne 0 %then %do;
	proc contents data=&amp;amp;mylib.._ALL_ nods short;
	run;
%end;
%else %do;
	%put &amp;amp;mylib. NOT assigned;
%end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Aug 2023 12:32:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Changing-project-s-behavior-at-runtime/m-p/888925#M43444</guid>
      <dc:creator>lc_isp</dc:creator>
      <dc:date>2023-08-11T12:32:24Z</dc:date>
    </item>
    <item>
      <title>Re: Changing project's behavior at runtime</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Changing-project-s-behavior-at-runtime/m-p/889002#M43449</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/267902"&gt;@lc_isp&lt;/a&gt;&amp;nbsp;If you make &amp;amp;libexist global then you need to set it to zero before calling the macro as else the macro will only in the first call return a valid result. One of the reasons to use a macro is its reusability meaning you only need to define it once per session but then can call it many times. For that reason I fail to see how your changes would be an improvement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Aug 2023 22:43:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Changing-project-s-behavior-at-runtime/m-p/889002#M43449</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-08-11T22:43:22Z</dc:date>
    </item>
    <item>
      <title>Re: Changing project's behavior at runtime</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Changing-project-s-behavior-at-runtime/m-p/889184#M43456</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;my SAS programming knowledge is sure lesser than yours: I thought the&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&lt;STRONG&gt;%let libexist=0;&lt;/STRONG&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;in macro's body, worked that way. I mean: if I remove the "&lt;EM&gt;%local libexist&lt;/EM&gt;" from the macro, it should refer to the &lt;STRONG&gt;global&lt;/STRONG&gt; one, right?&lt;/P&gt;</description>
      <pubDate>Mon, 14 Aug 2023 13:13:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Changing-project-s-behavior-at-runtime/m-p/889184#M43456</guid>
      <dc:creator>lc_isp</dc:creator>
      <dc:date>2023-08-14T13:13:50Z</dc:date>
    </item>
    <item>
      <title>Re: Changing project's behavior at runtime</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Changing-project-s-behavior-at-runtime/m-p/889186#M43457</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/267902"&gt;@lc_isp&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;my SAS programming knowledge is sure lesser than yours: I thought the&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&lt;STRONG&gt;%let libexist=0;&lt;/STRONG&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;in macro's body, worked that way. I mean: if I remove the "&lt;EM&gt;%local libexist&lt;/EM&gt;" from the macro, it should refer to the &lt;STRONG&gt;global&lt;/STRONG&gt; one, right?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Yes, if there is a global macro variable LIBEXIST and your remove the %LOCAL statement, then a reference to LIBEXIST in the macro will point to the global version.&amp;nbsp; But it's not clear to me if you are gaining any benefit from having a global macro variable.&amp;nbsp; Note that you seem to be using it after your macro call, to see if the code worked.&amp;nbsp; But if the libref didn't exist before the macro call, and the macro successfully generates the LIBNAME statement, LIBEXIST will still be 0 after the macro call.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I noticed there is a LIBREF function which returns 0 if a libref is not assigned.&amp;nbsp; I wonder if you could accomplish your goal with (untested):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if (%sysfunc(libref(gn777A)) ne 0) %then %do ;
  libname gn777A meta liburi="SASLibrary?@libref='gn777A'" metaout=data ;
%end ;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then if you want to check that the library exists after running the code, you could add an assertion:&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if NOT (%sysfunc(libref(gn777A)) = 0) %then %do ;
  %put ERROR: libref gn777A could not be assigned! ;
%end ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Aug 2023 13:35:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Changing-project-s-behavior-at-runtime/m-p/889186#M43457</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2023-08-14T13:35:54Z</dc:date>
    </item>
    <item>
      <title>Re: Changing project's behavior at runtime</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Changing-project-s-behavior-at-runtime/m-p/889191#M43458</link>
      <description>&lt;P&gt;The reason why I'm using a global, instead of a local value, is to be able to test it, if I need, into other project steps without the need to re-call the testing macro (of course it can be done, if one needs or have doubts the library is still assigned, at that further point).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;About&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;code (and aside of my little modification), as far as I tested it, it worked very well, as well as I'm replacing my original one (the one where I had the problem which made me to open this thread) with his one.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In my previous tests, with &lt;STRONG&gt;my&lt;/STRONG&gt; code, I was seeing that, even when the library have been assigned by using&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname &amp;amp;library_name. META LIBRARY="&amp;amp;library_name." metauser=&amp;amp;_METAUSER.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;when I re-tested it a little later, the project gave the error like it wasn't assigned. But, when I gone to see the library interactively, right-clicking on it, the contextual menu gave me the &lt;EM&gt;&lt;STRONG&gt;un&lt;/STRONG&gt;assign&lt;/EM&gt; item, which seems not congruent with the "library not assigned" error my program received.&lt;/P&gt;
&lt;P&gt;That's why I thought to use proc metalib&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc metalib;
	omr (library="&amp;amp;library_name.");
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;as, even when it fails ('cause of my auth lack), it seems syncing metadata: result is the next test works&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc contents data=&amp;amp;lib..&amp;amp;tab.;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;'s code solved the problem at the root, it seems as, after the&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname &amp;amp;lib. meta liburi="SASLibrary?@libref='&amp;amp;lib.'" metaout=data;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;engaged if &amp;amp;libexist is 0 only, further tests correctly access the library, all the solution into a single macro, also.&lt;/P&gt;
&lt;P&gt;I could then figure how to modify it, to test multiple libraries but, for a single one, it's working already.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;About the "assertion" part: it could be more correct to have &lt;STRONG&gt;&lt;EM&gt;another test&lt;/EM&gt;&lt;/STRONG&gt;, after the above libname... assignment, so to be sure the library is assigned, after that call (I know I'm assuming it is, right now) to end with librassigned = 1 to one side or the error message (plus libassigned = 0) to the other, you're right on that.&lt;/P&gt;</description>
      <pubDate>Mon, 14 Aug 2023 13:58:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Changing-project-s-behavior-at-runtime/m-p/889191#M43458</guid>
      <dc:creator>lc_isp</dc:creator>
      <dc:date>2023-08-14T13:58:15Z</dc:date>
    </item>
  </channel>
</rss>

