Unlike PROC PRINT, which defaults to showing observation numbers, the table.fetch action often returns an _Index_ column that represents the row's position on a specific worker node, which can look random in a distributed environment. To get a cleaner output similar to a standard report, you can add the parameter index=FALSE to your statement (e.g., table.fetch / table='ventes' index=FALSE;) to hide this technical column.
To use it like a pro, remember these three best practices:
Be Resource Efficient: Always use the to= parameter to limit your results. Fetching millions of rows to your client session can cause significant latency or memory issues; stick to the first 20–100 rows for quick verification.
Leverage CAS-Side Processing: Use the where and sortBy parameters directly within the action. This ensures filtering and sorting happen in-memory within the CAS server before any data is transferred to your interface.
Enhance Readability: Take advantage of computedVars and format=true. By applying formats directly in the fetch action, you can transform raw data into business-ready insights (e.g., converting scores to "Pass/Fail" statuses) instantly without creating a new physical table.
Type : CREATION_INTERNE
Examples use generated data (datalines) or SASHELP tables loaded into CAS.
| 1 | /* Création d'une table de démonstration en mémoire CAS */ |
| 2 | DATA casuser.ma_table; |
| 3 | INPUT ID Nom $ Age Score; |
| 4 | DATALINES; |
| 5 | 1 Alice 25 85 |
| 6 | 2 Bob 30 92 |
| 7 | 3 Charlie 22 78 |
| 8 | 4 Diana 28 95 |
| 9 | 5 Eve 35 88 |
| 10 | ; |
| 11 | RUN; |
| 12 | |
| 13 | PROC CAS; |
| 14 | SESSION casauto; |
| 15 | /* Afficher les 3 premières lignes de la table */ |
| 16 | TABLE.fetch / TABLE='ma_table', to=3; |
| 17 | RUN; |
| 18 | QUIT; |

| 1 | /* Création d'une table de démonstration en mémoire CAS */ |
| 2 | DATA casuser.ventes; |
| 3 | INPUT ID Produit $ Quantite Prix; |
| 4 | DATALINES; |
| 5 | 1 A 10 100 |
| 6 | 2 B 5 150 |
| 7 | 3 A 20 100 |
| 8 | 4 C 8 200 |
| 9 | 5 B 12 150 |
| 10 | 6 A 15 100 |
| 11 | ; |
| 12 | RUN; |
| 13 | |
| 14 | PROC CAS; |
| 15 | SESSION casauto; |
| 16 | /* Afficher les lignes pour le produit 'A', en sélectionnant seulement 'ID' et 'Quantite' */ |
| 17 | TABLE.fetch / |
| 18 | TABLE='ventes', |
| 19 | where='Produit="A"', |
| 20 | vars={'ID', 'Quantite'}; |
| 21 | RUN; |
| 22 | QUIT; |

| 1 | /* Création d'une table de démonstration en mémoire CAS */ |
| 2 | DATA casuser.etudiants; |
| 3 | INPUT Nom $ Matiere $ Note; |
| 4 | DATALINES; |
| 5 | Alice Math 90 |
| 6 | Bob Info 85 |
| 7 | Alice Info 92 |
| 8 | Charlie Math 78 |
| 9 | Bob Math 88 |
| 10 | ; |
| 11 | RUN; |
| 12 | |
| 13 | /* Création d'un format personnalisé pour les notes */ |
| 14 | PROC FORMAT; |
| 15 | value note_fmt |
| 16 | low-60 = 'Échec' |
| 17 | 61-75 = 'Passable' |
| 18 | 76-100 = 'Excellent'; |
| 19 | QUIT; |
| 20 | |
| 21 | PROC CAS; |
| 22 | SESSION casauto; |
| 23 | /* Charger le format en CAS */ |
| 24 | BUILTINS.uploadformat / |
| 25 | caslib='casuser', |
| 26 | fmtlibname='formats'; |
| 27 | |
| 28 | /* Afficher les données triées par 'Note' décroissante, avec une variable calculée et formatée */ |
| 29 | TABLE.fetch / |
| 30 | TABLE='etudiants', |
| 31 | sortBy={{name='Note', order='descending'}}, |
| 32 | computedVars={{name='Statut', expression='put(Note, note_fmt.)'}}, |
| 33 | computedVarsProgram='data; set etudiants; run;', |
| 34 | FORMAT=true, |
| 35 | to=5; |
| 36 | RUN; |
| 37 | QUIT; |

| 1 | PROC CAS; |
| 2 | SESSION casauto; |
| 3 | |
| 4 | /* Charger la table IRIS de SASHELP dans la caslib 'casuser' */ |
| 5 | TABLE.loadtable / |
| 6 | caslib='casuser', |
| 7 | path='iris.sashdat', |
| 8 | casout={name='IRIS_CAS', replace=true}; |
| 9 | |
| 10 | /* Afficher les informations de la table chargée */ |
| 11 | TABLE.tableinfo / TABLE='IRIS_CAS'; |
| 12 | |
| 13 | /* Afficher les 10 premières lignes de la table chargée */ |
| 14 | TABLE.fetch / TABLE='IRIS_CAS', to=10; |
| 15 | |
| 16 | /* Nettoyer la table chargée après utilisation (optionnel) */ |
| 17 | TABLE.droptable / caslib='casuser', name='IRIS_CAS'; |
| 18 | RUN; |
| 19 | QUIT; |
