<?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: Libname ... postgres ... defer=yes: Process that establishes connection in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Libname-postgres-defer-yes-Process-that-establishes-connection/m-p/884474#M349429</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My IT environment is totally different, but maybe one of the five suggestions below is helpful anyway ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Ideally something that doesn't create output.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;The &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/proc/p1v2467vdjbp7xn1222c7t3sejz3.htm#n1x7c61arqfpc5n1nnhy5r36sjoz" target="_blank" rel="noopener"&gt;NOPRINT option&lt;/A&gt; could suppress the PROC CONTENTS output.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;/LI&gt;
&lt;LI&gt;Have you tried any of these functions?&lt;BR /&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
if libref('mydb');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/LI&gt;
&lt;LI&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
rc=exist('mydb.somename');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/LI&gt;
&lt;LI&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
rc=rename('mydb.nonex', 'nonex');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/LI&gt;
&lt;LI&gt;&lt;A href="https://communities.sas.com/t5/SAS-Programming/When-are-dictionary-tables-updated/m-p/647228#M193670" target="_blank" rel="noopener"&gt;Sometimes&lt;/A&gt; using the SASHELP views (rather than the DICTIONARY tables) makes a difference.&lt;BR /&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
set sashelp.vlibnam;
where libname="MYDB" and sysname='Schema/Owner';
call symputx('pg_schema',sysvalue);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/LI&gt;
&lt;/OL&gt;</description>
    <pubDate>Wed, 12 Jul 2023 13:31:41 GMT</pubDate>
    <dc:creator>FreelanceReinh</dc:creator>
    <dc:date>2023-07-12T13:31:41Z</dc:date>
    <item>
      <title>Libname ... postgres ... defer=yes: Process that establishes connection</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Libname-postgres-defer-yes-Process-that-establishes-connection/m-p/884452#M349421</link>
      <description>&lt;P&gt;Hi all,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm looking for an approach as simple as possible that forces SAS to establish a connection to postgres for a pre-assigned library defined in metadata with option defer=yes set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Problem&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;If I run below code then the query returns zero rows and macro variable &amp;amp;pg_schema is blank. It appears the library doesn't appear in the dictionary table prior to the database connection being established.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname mydb POSTGRES ... DEFER=YES;
%let pg_schema=;
proc sql noprint;
  select sysvalue into :pg_schema trimmed 
  from dictionary.libnames
  where libname="MYDB" and sysname='Schema/Owner' 
  ;
quit;
%put &amp;amp;=pg_schema;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If I "do" something that accesses the database then the connection gets established and the macro variable gets populated. In below code the "do" is Proc Contents&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname mydb POSTGRES ... DEFER=YES;

proc contents data=mydb._all_;quit;

%let pg_schema=;
proc sql noprint;
  select sysvalue into :pg_schema trimmed 
  from dictionary.libnames
  where libname="MYDB" and sysname='Schema/Owner' 
  ;
quit;
%put &amp;amp;=pg_schema;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The "funny" thing: If I run the first version of my code out of SAS EG then things work and the macro variable gets populated.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My code needs to work when running under SAS IRM (SAS Infrastructure for Risk Management) under SAS9.4 M7/RHEL. IRM does process orchestration.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Under IRM the first code version without Proc Contents returns zero rows, the version with Proc Contents works.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;What I'm looking for&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Something simpler than Proc Contents to establish the connection. There can be quite a few tables under a schema. Assume that I don't know any table names in advance.&lt;/P&gt;
&lt;P&gt;...or may-be I just do: options obs=1;proc contents ...; options obs=max&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any other simple syntax ideas welcome. Ideally something that doesn't create output.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jul 2023 10:19:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Libname-postgres-defer-yes-Process-that-establishes-connection/m-p/884452#M349421</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-07-12T10:19:58Z</dc:date>
    </item>
    <item>
      <title>Re: Libname ... postgres ... defer=yes: Process that establishes connection</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Libname-postgres-defer-yes-Process-that-establishes-connection/m-p/884474#M349429</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My IT environment is totally different, but maybe one of the five suggestions below is helpful anyway ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Ideally something that doesn't create output.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;The &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/proc/p1v2467vdjbp7xn1222c7t3sejz3.htm#n1x7c61arqfpc5n1nnhy5r36sjoz" target="_blank" rel="noopener"&gt;NOPRINT option&lt;/A&gt; could suppress the PROC CONTENTS output.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;/LI&gt;
&lt;LI&gt;Have you tried any of these functions?&lt;BR /&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
if libref('mydb');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/LI&gt;
&lt;LI&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
rc=exist('mydb.somename');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/LI&gt;
&lt;LI&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
rc=rename('mydb.nonex', 'nonex');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/LI&gt;
&lt;LI&gt;&lt;A href="https://communities.sas.com/t5/SAS-Programming/When-are-dictionary-tables-updated/m-p/647228#M193670" target="_blank" rel="noopener"&gt;Sometimes&lt;/A&gt; using the SASHELP views (rather than the DICTIONARY tables) makes a difference.&lt;BR /&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
set sashelp.vlibnam;
where libname="MYDB" and sysname='Schema/Owner';
call symputx('pg_schema',sysvalue);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/LI&gt;
&lt;/OL&gt;</description>
      <pubDate>Wed, 12 Jul 2023 13:31:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Libname-postgres-defer-yes-Process-that-establishes-connection/m-p/884474#M349429</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2023-07-12T13:31:41Z</dc:date>
    </item>
    <item>
      <title>Re: Libname ... postgres ... defer=yes: Process that establishes connection</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Libname-postgres-defer-yes-Process-that-establishes-connection/m-p/885013#M349676</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for all these proposals. I've done quite a few trials but in my environment and under the assumption that I don't know a table name in advance the only two approaches that I could identify working would either be a proc contents data=&amp;lt;libref&amp;gt;._all_ or then to query SAS metadata to retrieve the schema name defined with the library definition.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In real life:&amp;nbsp;&lt;SPAN&gt;I've taken a step back and decided that if a developer knows the libref then it's not too much to ask to also figure out the schema name. I've created now a parameter to my macro for the schema name and don't try to retrieve it anymore. And I've set the default of the schema name to what it needs to be in potentially all the cases where this macro gets used.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I went initially for something dynamic because the installers at my site managed to call things sometimes different in different environments - luckily the schema names are the same in all environments so one can develop code that doesn't change when pushing it into higher environments.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Jul 2023 10:26:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Libname-postgres-defer-yes-Process-that-establishes-connection/m-p/885013#M349676</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-07-17T10:26:23Z</dc:date>
    </item>
  </channel>
</rss>

