session batchresults

Standard Workflow for Detaching and Retrieving Marketing Campaign Analysis Results

Scénario de test & Cas d'usage

Business Context

A marketing analyst needs to run a complex customer segmentation analysis (using the `fastknn` action) which takes a considerable amount of time. They want to start the job, disconnect their client session to work on other tasks, and retrieve the results later once the analysis is complete. This ensures that their local resources are not tied up and improves productivity.
About the Set : session

Management of the CAS session state.

Discover all actions of session
Data Preparation

Create a sample customer table with demographic and behavioral data for segmentation. The table contains 1 million records to simulate a moderately long-running analysis.

Copied!
1DATA casuser.customer_data;
2 call streaminit(123);
3 DO i = 1 to 1000000;
4 customer_id = i;
5 age = 20 + floor(rand('UNIFORM') * 50);
6 income = 30000 + floor(rand('UNIFORM') * 100000);
7 recency = floor(rand('UNIFORM')*365);
8 frequency = 1 + floor(rand('UNIFORM')*50);
9 monetary = 10 + rand('UNIFORM')*500;
10 OUTPUT;
11 END;
12RUN;

Étapes de réalisation

1
Start a named CAS session 'analyst_session', load the required action set, and run the data preparation step.
Copied!
1cas analyst_session name='analyst_session';
2PROC CAS;
3 SESSION analyst_session;
4 ACTION BUILTINS.LOADACTIONSET / actionSet='kClus';
5 /* Assume data_prep code has been run here */
6 ACTION TABLE.tableInfo / caslib='casuser' TABLE='customer_data';
7RUN;
2
In 'analyst_session', start the 'fastknn' analysis asynchronously and print the session's UUID.
Copied!
1PROC CAS;
2 SESSION analyst_session;
3 ACTION kClus.fastknn RESULT=knn_job /
4 TABLE={name='customer_data'},
5 inputs={{name='age'}, {name='income'}, {name='recency'}},
6 k=5,
7 OUTPUT={casout={name='customer_segments', replace=true}, copyvars='ALL'},
8 async='knn_analysis_job';
9 PRINT 'Analyst Session UUID: ' || SESSION.sessionId();
10RUN;
3
In a separate session ('admin_session'), use the UUID from the previous step to switch the running job to batch mode.
Copied!
1cas admin_session name='admin_session';
2PROC CAS;
3 SESSION admin_session;
4 /* Replace 'uuid-from-analyst-session' with the actual UUID */
5 ACTION SESSION.batchresults / uuid='uuid-from-analyst-session';
6RUN;
4
Later, from any session, check the status of the job until it is completed.
Copied!
1PROC CAS;
2 /* This step might be run multiple times */
3 ACTION SESSION.actionstatus / name='knn_analysis_job';
4RUN;
5
Once the job is complete, fetch the results and view the output table.
Copied!
1PROC CAS;
2 ACTION SESSION.fetchresult / name='knn_analysis_job';
3 ACTION TABLE.fetch / TABLE={name='customer_segments', caslib='casuser'}, to=10;
4RUN;

Expected Result


The `batchresults` action should successfully detach the 'knn_analysis_job'. The 'analyst_session' client is immediately freed. The `actionstatus` call will initially show the job as 'running' and later as 'completed'. The `fetchresult` call will retrieve the full results dictionary of the `fastknn` action, and the 'customer_segments' output table will be created and populated in the 'casuser' caslib.