Hi Bart, this looks like a version issue. I wrote the blog using SAS Viya release Stable 2023.10. SAS Viya for Learners is a older.

I tested the code and got the same error and then found another issue.

1. First issue is creating the UDF. I played around with the action and realized that when you have the appendTable option it won't create the function table in Viya 3.5. Remove the appendTable option and it worked. Not sure why that happens.

2. Once you create the UDF there is another issue. When you go to apply the UDF in the DATA step I couldn't get it to work. It seems like you can't use the DATA step to apply a UDF in Viya 3.5 (i'd have to test this more for more information). Instead, it seems like you have to use the runProgram action (https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/caspg/cas-fcmpact-runprogram.htm) instead. It works like the DATA step.

Here is the solution code for you.

libname casuser cas caslib='casuser';

/* Create fake data */
data casuser.test_table;
do value= 1,2,3,4,5;
output;
end;
run;
proc print data=casuser.test_table;
run;

options msglevel=I;
/* I removed the appendTable option */
proc cas;
fcmpact.addRoutines /
routineCode = '
function fcmpFunction (x);
return ( x * 10 );
endfunc;
',
saveTable = True,
funcTable = {
name = "my_udfs_sas",
caslib = 'casuser',
replace = TRUE
};
quit;

/* The table my_udfs_sas and my_udfs_sas.sashdat file is now created. */
proc casutil incaslib = 'casuser';
list tables;
list files;
quit;

/* Set options to use the UDF */
options sessopts=(cmplib='casuser.my_udfs_sas') cmplib=(casuser.my_udfs_sas);

/* Check cmplib option in CAS and confirm it is set to casuser.my_udfs_sas*/
proc cas;
listsessopts;
quit;

/* The DATA step with the UDF errors out in Viya 3.5 */
data casuser.new_table;
set casuser.test_table;
newvalue = fcmpFunction(Value);
run;

/* Looks like you have to use this method instead of the familiar DATA step in Viya 3.5 */
proc cas;
fcmpact.runProgram /
/* Add data step statements here */
routineCode = "
newValue = fcmpFunction(Value);
other = 'Hi!';
if newValue > 40 then value_group = 'High';
else value_group = 'low';
",
inputData={name="test_table", caslib = 'casuser'},
outputData={name="test_table_new", caslib = 'casuser', replace=true};
quit;

proc print data=casuser.test_table_new;
run;