When using the WHERE parameter within the table.append action, the filtering logic is pushed down to the CAS nodes where the data resides; this means SAS only moves the relevant rows across the network to the target table, significantly reducing communication overhead compared to filtering the data after it has already been appended.
The CAS 'table.append' action is used to transfer rows from a source table (in-memory or promoted) to an existing target table in CAS. The 'WHERE' parameter in the 'source' option allows specifying a logical condition. Only rows from the source table that satisfy this condition will be added to the target table. Execution occurs in distributed memory on the CAS server, which is optimized for large data volumes. The target table must already exist.
Data Analysis
Type : CREATION_INTERNE
Examples use generated data (datalines) or SASHELP tables loaded into CAS.
1 Code Block
PROC CAS / DATA STEP Data
Explanation : This example initializes two CAS tables, 'class_source' (from SASHELP.CLASS) and 'class_target' (empty). It then uses 'table.append' to add all rows from 'class_source' to 'class_target' without any filtering condition. Finally, it displays the content of the target table.
Copied!
/* Charger la table SASHELP.CLASS en CAS */
proc casutil;
load data=sashelp.class outcaslib="casuser" casout="class_source" replace;
run;
/* Créer une table cible vide avec la même structure en CAS */
data casuser.class_target;
set casuser.class_source(obs=0);
run;
proc cas;
/* Ajouter toutes les lignes de class_source à class_target */
table.append /
source={caslib='casuser', name='class_source'}
target={caslib='casuser', name='class_target'};
run;
/* Vérifier le contenu de la table cible */
proc print data=casuser.class_target;
run;
/* Créer une table cible vide avec la même structure en CAS */
7
DATA casuser.class_target;
8
SET casuser.class_source(obs=0);
9
RUN;
10
11
PROC CAS;
12
/* Ajouter toutes les lignes de class_source à class_target */
13
TABLE.append /
14
SOURCE={caslib='casuser', name='class_source'}
15
target={caslib='casuser', name='class_target'};
16
RUN;
17
18
/* Vérifier le contenu de la table cible */
19
PROC PRINTDATA=casuser.class_target;
20
RUN;
2 Code Block
PROC CAS / DATA STEP Data
Explanation : This example loads the complete SASHELP.CLASS table into CAS as 'class_full'. It creates a 'class_filtered' table with some initial observations. Then, it uses 'table.append' with the 'where="Age >= 15"' parameter to add only the observations from 'class_full' where the age is 15 or older to the 'class_filtered' table. The final content of 'class_filtered' is displayed.
Copied!
/* Charger la table SASHELP.CLASS en CAS */
proc casutil;
load data=sashelp.class outcaslib="casuser" casout="class_full" replace;
run;
/* Créer une table cible avec quelques données initiales */
data casuser.class_filtered;
input Name $ Sex $ Age Height Weight;
datalines;
Alfred M 14 69.0 112.5
Alice F 13 56.5 84.0
;
run;
proc cas;
/* Ajouter uniquement les étudiants dont l'âge est supérieur ou égal à 15 ans */
table.append /
source={caslib='casuser', name='class_full', where="Age >= 15"}
target={caslib='casuser', name='class_filtered'};
run;
/* Vérifier le contenu de la table cible */
proc print data=casuser.class_filtered;
run;
Explanation : This example demonstrates an advanced case where data is first transformed into a new CAS table ('students_processed') by calculating an average score and status. Then, 'table.append' is used to add only the observations from 'students_processed' that satisfy a complex 'WHERE' condition to the 'high_achievers' table: the status must be 'Excellent' AND the gender must be 'F'. This illustrates how to combine data preparation steps with conditional appending.
Copied!
/* Créer une table source avec des données brutes en CAS */
data casuser.students_raw;
input StudentID Name $ Gender $ Score1 Score2;
datalines;
101 Jean M 85 92
102 Marie F 78 88
103 Pierre M 91 75
104 Sophie F 65 95
105 Paul M 80 81
;
run;
/* Créer une table cible avec des données initiales */
data casuser.high_achievers;
input StudentID Name $ Gender $ AverageScore Status$;
datalines;
201 Marc M 90 Initial
;
run;
proc cas;
/* Calculer le score moyen et déterminer un statut avant d'ajouter */
data casuser.students_processed;
set casuser.students_raw;
AverageScore = (Score1 + Score2) / 2;
if AverageScore >= 85 then Status = 'Excellent';
else Status = 'Good';
run;
/* Ajouter uniquement les étudiants 'Excellent' et de sexe féminin */
table.append /
source={caslib='casuser', name='students_processed', where="Status = 'Excellent' AND Gender = 'F'"}
target={caslib='casuser', name='high_achievers'};
run;
/* Vérifier le contenu de la table cible */
proc print data=casuser.high_achievers;
run;
1
/* Créer une table source avec des données brutes en CAS */
2
DATA casuser.students_raw;
3
INPUT StudentID Name $ Gender $ Score1 Score2;
4
DATALINES;
5
101 Jean M 8592
6
102 Marie F 7888
7
103 Pierre M 9175
8
104 Sophie F 6595
9
105 Paul M 8081
10
;
11
RUN;
12
13
/* Créer une table cible avec des données initiales */
14
DATA casuser.high_achievers;
15
INPUT StudentID Name $ Gender $ AverageScore STATUS$;
16
DATALINES;
17
201 Marc M 90 Initial
18
;
19
RUN;
20
21
PROC CAS;
22
/* Calculer le score moyen et déterminer un statut avant d'ajouter */
23
DATA casuser.students_processed;
24
SET casuser.students_raw;
25
AverageScore = (Score1 + Score2) / 2;
26
IF AverageScore >= 85THENSTATUS = 'Excellent';
27
ELSESTATUS = 'Good';
28
RUN;
29
30
/* Ajouter uniquement les étudiants 'Excellent' et de sexe féminin */
31
TABLE.append /
32
SOURCE={caslib='casuser', name='students_processed', where="Status = 'Excellent' AND Gender = 'F'"}
33
target={caslib='casuser', name='high_achievers'};
34
RUN;
35
36
/* Vérifier le contenu de la table cible */
37
PROC PRINTDATA=casuser.high_achievers;
38
RUN;
4 Code Block
PROC CAS / DATA STEP Data
Explanation : This example creates a temporary SAS table 'temp_large' with 1000 observations, then loads and 'promotes' it as 'large_data_source' in CAS. It also creates an empty promoted target table 'filtered_promoted'. It then uses 'table.append' to add to 'filtered_promoted' only the rows where 'Value < 10'. The Viya/CAS aspect is highlighted by the use of promoted tables which are persistent beyond the current session, and a final cleanup block to drop all CAS tables created during the examples.
Copied!
/* Créer une table source temporaire avec un grand nombre d'observations */
data _null_;
do i = 1 to 1000;
ID = i;
Value = mod(i, 100);
output;
end;
run;
proc casutil;
load data=work.temp_large outcaslib="casuser" casout="large_data_source" promote replace;
run;
/* Créer une table cible promotée vide */
proc casutil;
load data=work.temp_large(obs=0) outcaslib="casuser" casout="filtered_promoted" promote replace;
run;
proc cas;
/* Ajouter des lignes à la table promotée 'filtered_promoted' avec une condition WHERE */
/* L'utilisation de 'promote' assure la persistance de la table au-delà de la session */
table.append /
source={caslib='casuser', name='large_data_source', where="Value < 10"}
target={caslib='casuser', name='filtered_promoted'};
run;
/* Vérifier le contenu de la table cible promotée */
proc print data=casuser.filtered_promoted;
run;
/* Nettoyage : supprimer les tables CAS après utilisation */
proc cas;
table.dropTable / caslib='casuser', name='large_data_source';
table.dropTable / caslib='casuser', name='filtered_promoted';
table.dropTable / caslib='casuser', name='students_raw';
table.dropTable / caslib='casuser', name='high_achievers';
table.dropTable / caslib='casuser', name='class_source';
table.dropTable / caslib='casuser', name='class_target';
table.dropTable / caslib='casuser', name='class_full';
table.dropTable / caslib='casuser', name='class_filtered';
table.dropTable / caslib='casuser', name='students_processed';
run;
1
/* Créer une table source temporaire avec un grand nombre d'observations */
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.
Related Documentation
Aucune documentation spécifique pour cette catégorie.
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. WeAreCAS is an independent community site and is not affiliated with SAS Institute Inc.
This site uses technical and analytical cookies to improve your experience.
Read more.