table alterTable

Marketing Campaign Data Refinement

Scénario de test & Cas d'usage

Business Context

A marketing team has just received a new list of customer leads. The data is structurally sound but uses inconsistent and non-standard column names and formats. The goal is to clean up the table's metadata to make it ready for a segmentation analysis.
About the Set : table

Loading, saving, and managing in-memory tables.

Discover all actions of table
Data Preparation

Create a sample customer leads table with cryptic column names and raw data types that need formatting.

Copied!
1DATA casuser.NEW_LEADS_Q4;
2 LENGTH leadid $10 fname $20 lname $25 last_contact_str $10 score_val 8;
3 INFILE DATALINES delimiter=',';
4 INPUT leadid $ fname $ lname $ last_contact_str $ region $ score_val;
5 DATALINES;
6LDG-001,John,Smith,2025-10-05,NA,780
7LDG-002,Jane,Doe,2025-11-12,EU,910
8LDG-003,Peter,Jones,2025-09-21,NA,650
9LDG-004,Mary,Williams,2025-11-01,APAC,880
10;
11RUN;

Étapes de réalisation

1
Load the initial leads table into CAS to make it available for alteration.
Copied!
1 
2PROC CAS;
3TABLE.loadTable / caslib='casuser' path='NEW_LEADS_Q4.sashdat' casout={name='new_leads_q4', replace=true};
4RUN;
5 
2
Perform multiple column modifications: rename columns for clarity, add descriptive labels, and apply a proper date format.
Copied!
1PROC CAS;
2 TABLE.alterTable /
3 caslib='casuser'
4 name='new_leads_q4'
5 columns={
6 {name='fname', rename='FirstName', label='Customer First Name'},
7 {name='lname', rename='LastName', label='Customer Last Name'},
8 {name='last_contact_str', rename='LastContactDate', label='Date of Last Contact', FORMAT='DATE9.'},
9 {name='score_val', rename='LeadScore', label='Lead Qualification Score'}
10 };
11RUN;
3
Rename the entire table and add a descriptive label to signify its new status as a cleaned dataset.
Copied!
1PROC CAS;
2 TABLE.alterTable /
3 caslib='casuser'
4 name='new_leads_q4'
5 rename='Cleaned_Leads_For_Analysis'
6 label='Q4 Customer Leads - Cleaned and Ready for Segmentation';
7RUN;
4
Verify the changes by checking the column information of the newly renamed table.
Copied!
1 
2PROC CAS;
3TABLE.columnInfo / TABLE='Cleaned_Leads_For_Analysis';
4RUN;
5 

Expected Result


The final table 'Cleaned_Leads_For_Analysis' should have renamed columns (FirstName, LastName, LastContactDate, LeadScore), updated labels, and the 'LastContactDate' column should have a 'DATE9.' format applied. The table itself should have a new name and a descriptive label.