Scénario de test & Cas d'usage
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.
| 1 | DATA 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; |
| 12 | RUN; |
| 1 | cas analyst_session name='analyst_session'; |
| 2 | PROC 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'; |
| 7 | RUN; |
| 1 | PROC 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(); |
| 10 | RUN; |
| 1 | cas admin_session name='admin_session'; |
| 2 | PROC CAS; |
| 3 | SESSION admin_session; |
| 4 | /* Replace 'uuid-from-analyst-session' with the actual UUID */ |
| 5 | ACTION SESSION.batchresults / uuid='uuid-from-analyst-session'; |
| 6 | RUN; |
| 1 | PROC CAS; |
| 2 | /* This step might be run multiple times */ |
| 3 | ACTION SESSION.actionstatus / name='knn_analysis_job'; |
| 4 | RUN; |
| 1 | PROC CAS; |
| 2 | ACTION SESSION.fetchresult / name='knn_analysis_job'; |
| 3 | ACTION TABLE.fetch / TABLE={name='customer_segments', caslib='casuser'}, to=10; |
| 4 | RUN; |
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.