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.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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