SAS (Base SAS)+
data ENRLMENT;
infile datalines dlm='|' dsd missover;
input STUDY : $6. PT : $4. ICDT_RAW : $11. ENRLDT_RAW : $11. RANDDT_RAW : $11.;
label STUDY ='Study Number' PT ='Subject Identifier' ICDT_RAW ='Informed Consent Date' ENRLDT_RAW ='Enrollment Date' RANDDT_RAW ='Randomization Date';
format ;
datalines4;
CSG001|1001|1/JAN/2010||
CSG001|1002|1/JAN/2010|4/JAN/2010|
CSG001|1003|1/JAN/2010|3/JAN/2010|3/JAN/2010
CSG001|1004|1/JAN/2010|4/JAN/2010|5/JAN/2010
CSG001|1005|15/JAN/2010|1/FEB/2010|5/FEB/2010
CSG001|1006|18/FEB/2010|1/MAR/2010|1/MAR/2010
CSG001|1007|4/APR/2010|14/APR/2010|14/APR/2010
CSG001|1008|20/JUN/2010|26/JUN/2010|27/JUN/2010
;;;;
run;
data enrl01;
set enrlment;
array rvars[*] icdt_raw enrldt_raw randdt_raw;
do i=1 to dim(rvars);
rvars[i]=translate(rvars[i],' ','/');
end;
run;- In SAS, the ARRAY statement lets us name a list of variables once and then refer to them by an index inside a DO loop.
array rvars[*] icdt_raw enrldt_raw randdt_raw;creates an array namedrvarsthat points at the three raw date columns;[*]tells SAS to size the array from the variable list.do i = 1 to dim(rvars);loops from 1 to the number of elements in the array —dim(rvars)is more robust than hard-coding 3.rvars[i] = translate(rvars[i], ' ', '/');runs the TRANSLATE function on the i-th column — replacing/with a space.- The array members are aliases for the real columns, so assigning back through the array updates the underlying variables in the output dataset.
- After running, ENRL01 has the same columns as ENRLMENT, with every
/in the raw date columns replaced by a space. - Extending the logic to more columns is a one-line edit — add names to the ARRAY statement and the loop keeps working.