Introduction
This section discusses how to use restaf and restaflib methods to execute any cas action.
Methods
The two key methods of restaflib are:
- casSetup - creates a cas session.The only argument to this method is restaf store
- casActionRun - execute a specified cas action
casActionRun Method
This method runs a specified action.
Syntax
let actionResult = await restaflib.casActionRun(store, session, payload);
The arguments to this method are:
- store - the store object for restaf
- session - the session object from the casSetup method
- payload - An object with the schema describe below
The payload is:
{
action : name of the action - actionset.actionname,
data : The parameters(if any) for this action,
headers: Any special http headers for this action -
the table.upload action is the only action I am aware of that needs special headers
}
An typical payload for a datastep action is shown below
let p = {
action: "datastep.runCode",
data : {
code: "data casuser.score; x1=10;x2=20;x3=30; score1 = x1+x2+x3;run; "
}
};
The code to execute this action is:
let result = await restaflib.casActionRun(store, session, p);
... process results...
Processing results
The result from the action is the json returned by the Cas for any action. The content of the output will vary based on the action. See the documentation for the specific action for the details.
Note on table.upload action
This action is one of actions that requires information to be passed in the header. Below is an example for uploading a cars.csv file to casuser.cars:
let JSON\_Parameters = {
casout: {
caslib: 'casuser' /\* a valid caslib \*/,
name : 'cars' /\* name of output file on cas server \*/
},
importOptions: {
fileType: 'csv' /\* type of the file being uploaded \*/
}
};
let p = {
headers: { 'JSON-Parameters': JSON\_Parameters },
data : readFile(filename, fileType), /\* read file from a local csv file \*/
action : 'table.upload'
};
let actionResult = await restaflib.casActionRun(store, session, p);
... process results ...
Upload content
See https://github.com/sassoftware/restaf/tree/gen2/packages/viyacaddy/src for information on how to upload
- sas7bdat
- sashdat
- astore
- csv
- ds2 scoring code to a model table
- datastep scoring to a model table