SAS (Base SAS)+
data CLASS;
infile datalines dlm='|' dsd missover;
input Name : $8. Sex : $1. Age : best32. Height : best32. Weight : best32.;
label ;
format ;
datalines4;
Alfred|M|14|69|112.5
Alice|F|13|56.5|84
;;;;
run;
data renamed;
set class;
rename age=age_years height=height_in;
run;- To rename variables in SAS, we write a DATA step that reads the input with
SETand adds arenamestatement listingold = newpairs. rename age = age_in_years;changes the column name in the output only — the source dataset is untouched.- We can rename several columns in one statement:
rename age = age_in_years height = height_cm;. - An equally common form uses the dataset option:
set class (rename=(age = age_in_years));. The option form is handy when we want to rename while still in the SET step and do not want a separate rename line. - After the DATA step, the output dataset has the same rows and the same other columns, with just the Age name replaced.