?> batchresults - WeAreCAS
session

batchresults

Description

The `batchresults` action allows for changing the execution mode of a currently running action to batch mode. This is particularly useful for long-running actions, enabling the client to disconnect and retrieve the results later without interrupting the server-side processing. This action requires the UUID of the session where the target action is executing.

session.batchresults <result=results> <status=rc> / uuid="string";
Settings
ParameterDescription
uuidSpecifies the unique identifier (UUID) of the session where the action to be switched to batch mode is currently running. This parameter is mandatory.
Data Preparation
Data Creation for Examples

This step is not directly required for the `batchresults` action itself, as it operates on sessions and actions rather than data. However, to demonstrate its use, we will initiate a long-running action, such as `simple.summary`, on a sample table. The following code creates a sample table `my_table` in the active caslib.

proc cas; 
  data casuser.my_table; 
    do i = 1 to 10000000; 
      x = rand('UNIFORM'); 
      y = rand('NORMAL'); 
      output; 
    end; 
  run; 
quit;

Examples

This example demonstrates how to start an action in one session, obtain its session UUID, and then use the `batchresults` action from another session to switch the first action to batch mode. This allows the original session to proceed with other tasks or disconnect.

SAS® / CAS Code
Copied!
1/* In Session 1 (long_running_action) */
2PROC CAS;
3 SESSION casauto name='long_running_action';
4 ACTION SIMPLE.summary / TABLE='my_table', async='summary_job';
5 PRINT SESSION.sessionId();
6RUN;
7 
8/* In Session 2, after getting the UUID from Session 1 */
9PROC CAS;
10 SESSION.batchresults / uuid='uuid-from-session-1';
11RUN;
Result :
The `batchresults` action will return a confirmation that the specified action has been switched to batch mode. The original session (`long_running_action`) will be freed from waiting for the `simple.summary` action to complete. The results of the summary can be fetched later using the job name `summary_job`.

This detailed example illustrates the full lifecycle: 1. Start a CAS session and a potentially long-running action asynchronously. 2. Retrieve the session's UUID. 3. In a separate session, use the `batchresults` action to detach from the running job. 4. Later, reconnect or use another session to check the status and fetch the results of the completed batch job.

SAS® / CAS Code
Copied!
1/* Step 1: Start the asynchronous action in Session A */
2CAS session_a;
3PROC CAS;
4 SESSION session_a name='session_a';
5 ACTION SIMPLE.summary RESULT=summary_job / TABLE='my_table', async='my_summary_job';
6 PRINT 'Session A UUID: ' || SESSION.sessionId();
7RUN;
8 
9/* Step 2: In a separate SAS session (Session B), use the UUID from Session A */
10CAS session_b;
11PROC CAS;
12 SESSION session_b name='session_b';
13 /* Replace 'uuid-from-session-a' with the actual UUID printed in Step 1 */
14 ACTION SESSION.batchresults / uuid='uuid-from-session-a';
15RUN;
16 
17/* Step 3: Later, in any session, check the job status and fetch results */
18PROC CAS;
19 ACTION SESSION.actionstatus / name='my_summary_job';
20 ACTION SESSION.fetchresult / name='my_summary_job';
21RUN;
Result :
Step 1 initiates the summary and prints the UUID of `session_a`. Step 2 will confirm that the action in `session_a` is now running in batch mode. Step 3 will first show the status of the job (e.g., 'running', 'completed'). Once completed, the `fetchresult` action will display the full result dictionary from the `simple.summary` action, just as if it had been run synchronously.

FAQ

What is the purpose of the `batchresults` action in SAS Viya?
What parameter is required for the `batchresults` action?
How do I use the `batchresults` action in CASL?
Can I switch an action in a different session to batch mode?