If you find that the default functionality provided in the Workflow Mutate block is not quite what you need, you can create and use custom SAS language functions with the FCMP procedure.
User-defined functions saved in a SAS language catalog can be used in a workflow. Functions should not be created in a SAS language block as part of the workflow. This is because running a workflow uses multiple instances of an Altair SLC engine. A function defined in a SAS language block is therefore not guaranteed to be available to all parts of a workflow.
Your function can be invoked by every instance of the engine if you save the catalog in the SASUSER library and then add that location to the CMPLIB system option for the active engine.
This example uses the exam_results.csv dataset from the supplied samples to create a new variable for the dataset using the Mutate block. A function is created that calculates how effective students were in their study and returns a result between 1 and 100 inclusive. The higher the score the more effective their use of time.
To invoke a user-defined function in a workflow:
proc fcmp outlib = sasuser.mylib.testfn; function howEffective(timespent, result); if result = 0 then nscore = 1; else if timespent = 0 then nscore = 0; else nscore = 1 / (1 + result / timespent); if nscore GE 1 then return 100; else if nscore LE 0 then return 0; else return nscore*100; endsub; run;
howEffective(hoursstudy, mockresult)
The Working Dataset created by the Mutate block contains three variables and can be linked to other blocks in your workflow. You can also use your defined functions in the SQL block and both user-defined functions and CALL routines in SAS language programs in the SAS block. For more information about using the FCMP procedure, see the Altair SLC Reference for Language Elements.