?>Array ( [id] => 183 ) Appending Marketing Campaign Responses - WeAreCAS
table addTable

Appending Marketing Campaign Responses

Scénario de test & Cas d'usage

Contexte Métier

A marketing analytics team needs to consolidate customer responses from multiple campaign waves into a single master table. The initial data is loaded, and subsequent data from a new wave must be appended without deleting the original records. This scenario tests the 'append' logic and the action's behavior when neither 'append' nor 'replace' is specified on an existing table.
Préparation des Données

Creation of two datasets for two marketing campaign waves.

Copié !
1DATA WORK.CAMPAIGN_WAVE1;
2 LENGTH customer_id $10 campaign_id $8;
3 FORMAT response_date date9.;
4 DO i = 1 to 150;
5 customer_id = 'CUST' || put(1000+i, z4.);
6 campaign_id = 'CAMP_Q4';
7 response_date = '15NOV2025'd - i;
8 OUTPUT;
9 END;
10RUN;
11 
12DATA WORK.CAMPAIGN_WAVE2;
13 LENGTH customer_id $10 campaign_id $8;
14 FORMAT response_date date9.;
15 DO i = 1 to 75;
16 customer_id = 'CUST' || put(2000+i, z4.);
17 campaign_id = 'CAMP_Q4X';
18 response_date = '22NOV2025'd - i;
19 OUTPUT;
20 END;
21RUN;

Étapes de réalisation

1
Load the first wave of campaign responses into the 'CUSTOMER_RESPONSES' table.
Copié !
1PROC CAS;
2 TABLE.addTable /
3 caslib='casuser'
4 TABLE='CUSTOMER_RESPONSES'
5 datatable='CAMPAIGN_WAVE1'
6 vars={{name='customer_id', type='varchar', LENGTH=10},
7 {name='campaign_id', type='varchar', LENGTH=8},
8 {name='response_date', type='double', FORMAT='DATE9.'}};
9RUN;
10QUIT;
2
Attempt to load the second wave of data without 'append' or 'replace'. This action should fail or produce a warning, leaving the original table untouched.
Copié !
1PROC CAS;
2 TABLE.addTable /
3 caslib='casuser'
4 TABLE='CUSTOMER_RESPONSES'
5 datatable='CAMPAIGN_WAVE2'
6 vars={{name='customer_id', type='varchar', LENGTH=10},
7 {name='campaign_id', type='varchar', LENGTH=8},
8 {name='response_date', type='double', FORMAT='DATE9.'}};
9 TABLE.tableInfo / name='CUSTOMER_RESPONSES'; /* Check row count */
10RUN;
11QUIT;
3
Correctly append the second wave of data using 'append=TRUE'.
Copié !
1PROC CAS;
2 TABLE.addTable /
3 caslib='casuser'
4 TABLE='CUSTOMER_RESPONSES'
5 datatable='CAMPAIGN_WAVE2'
6 append=TRUE
7 vars={{name='customer_id', type='varchar', LENGTH=10},
8 {name='campaign_id', type='varchar', LENGTH=8},
9 {name='response_date', type='double', FORMAT='DATE9.'}};
10RUN;
11QUIT;
4
Final verification: Check the total number of rows to confirm both datasets are present.
Copié !
1PROC CAS;
2 TABLE.tableInfo / caslib='casuser' name='CUSTOMER_RESPONSES';
3RUN;
4QUIT;

Résultat Attendu


Step 1 creates a table with 150 rows. Step 2 should generate an error/warning in the log stating the table exists, and the row count of 'CUSTOMER_RESPONSES' should remain 150. Step 3 should execute successfully. The final verification in Step 4 must show that the 'CUSTOMER_RESPONSES' table has a total of 225 rows (150 from wave 1 + 75 from wave 2).