<?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 Bug in proc sql and fcmp variable scope (SAS 9.4M8) in Developers</title>
    <link>https://communities.sas.com/t5/Developers/Bug-in-proc-sql-and-fcmp-variable-scope-SAS-9-4M8/m-p/906218#M6448</link>
    <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Not sure where to post this (recommendations welcome), but be aware of a bug in SAS when using proc fcmp functions in proc sql - the variable scopes are not resolved correctly and assignments to arguments within the fcmp functions are actually made to the arguments that are passed (despite a warning in the log stating that they're not). Here's a minimal reproducible example:&lt;/P&gt;&lt;DIV&gt;&lt;PRE&gt;&lt;CODE class=""&gt;proc fcmp outlib=work.functions.mre;
&amp;nbsp; &amp;nbsp; function get_a_value(arg $);
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; arg = "FromFcmp";
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return(0);
&amp;nbsp; &amp;nbsp; endsub;
run;
option CMPLIB=work.functions;
proc sql;
    create table example as select x, get_a_value(x) as y from (select "From Sql" as x from dictionary.libnames);
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Within the created data set (work.example) the value of x is "FromFcmp". The workaround is to assign the arguments of functions to local variables and manipulate those.&lt;/DIV&gt;</description>
    <pubDate>Tue, 05 Dec 2023 10:42:44 GMT</pubDate>
    <dc:creator>_rok_</dc:creator>
    <dc:date>2023-12-05T10:42:44Z</dc:date>
    <item>
      <title>Bug in proc sql and fcmp variable scope (SAS 9.4M8)</title>
      <link>https://communities.sas.com/t5/Developers/Bug-in-proc-sql-and-fcmp-variable-scope-SAS-9-4M8/m-p/906218#M6448</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Not sure where to post this (recommendations welcome), but be aware of a bug in SAS when using proc fcmp functions in proc sql - the variable scopes are not resolved correctly and assignments to arguments within the fcmp functions are actually made to the arguments that are passed (despite a warning in the log stating that they're not). Here's a minimal reproducible example:&lt;/P&gt;&lt;DIV&gt;&lt;PRE&gt;&lt;CODE class=""&gt;proc fcmp outlib=work.functions.mre;
&amp;nbsp; &amp;nbsp; function get_a_value(arg $);
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; arg = "FromFcmp";
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return(0);
&amp;nbsp; &amp;nbsp; endsub;
run;
option CMPLIB=work.functions;
proc sql;
    create table example as select x, get_a_value(x) as y from (select "From Sql" as x from dictionary.libnames);
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Within the created data set (work.example) the value of x is "FromFcmp". The workaround is to assign the arguments of functions to local variables and manipulate those.&lt;/DIV&gt;</description>
      <pubDate>Tue, 05 Dec 2023 10:42:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Developers/Bug-in-proc-sql-and-fcmp-variable-scope-SAS-9-4M8/m-p/906218#M6448</guid>
      <dc:creator>_rok_</dc:creator>
      <dc:date>2023-12-05T10:42:44Z</dc:date>
    </item>
    <item>
      <title>Re: Bug in proc sql and fcmp variable scope (SAS 9.4M8)</title>
      <link>https://communities.sas.com/t5/Developers/Bug-in-proc-sql-and-fcmp-variable-scope-SAS-9-4M8/m-p/906224#M6449</link>
      <description>&lt;P&gt;Interesting thing, wonder wether it is FCMP's problem or SQL's ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Because (what is "funny") in the datastep it works ok.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc fcmp outlib=work.functions.mre;
    function get_a_value(arg $);
        put "BEFORE: inside FCMP" arg ;
        arg = "FromFcmp";
        put "AFTER: inside FCMP" arg ;
        return(lengthn(arg));
    endsub;
run;
option CMPLIB=work.functions;

data example2;
  x = "From Sql";
  put _ALL_;
  y=get_a_value(x);
  put _ALL_;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;[EDIT:] I would go to SAS Tech. Support with that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Tue, 05 Dec 2023 11:16:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Developers/Bug-in-proc-sql-and-fcmp-variable-scope-SAS-9-4M8/m-p/906224#M6449</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2023-12-05T11:16:23Z</dc:date>
    </item>
    <item>
      <title>Re: Bug in proc sql and fcmp variable scope (SAS 9.4M8)</title>
      <link>https://communities.sas.com/t5/Developers/Bug-in-proc-sql-and-fcmp-variable-scope-SAS-9-4M8/m-p/906225#M6450</link>
      <description>&lt;P&gt;Contacting tech support is recommended, as it looks like either a very fancy feature or a bug.&lt;/P&gt;</description>
      <pubDate>Tue, 05 Dec 2023 11:27:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Developers/Bug-in-proc-sql-and-fcmp-variable-scope-SAS-9-4M8/m-p/906225#M6450</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2023-12-05T11:27:03Z</dc:date>
    </item>
  </channel>
</rss>

