BookmarkSubscribeRSS Feed
_rok_
Calcite | Level 5

Hi, 

 

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:

proc fcmp outlib=work.functions.mre;
    function get_a_value(arg $);
        arg = "FromFcmp";
        return(0);
    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;
 
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.
2 REPLIES 2
yabwon
Onyx | Level 15

Interesting thing, wonder wether it is FCMP's problem or SQL's ?

 

Because (what is "funny") in the datastep it works ok.

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;

 

[EDIT:] I would go to SAS Tech. Support with that.

 

Bart

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



andreas_lds
Jade | Level 19

Contacting tech support is recommended, as it looks like either a very fancy feature or a bug.

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1325 views
  • 7 likes
  • 3 in conversation