By saying you want to use the DATEPART
function, you are implying that your three existing variables are currently stored as SAS "date-time" values. So try this:
data have;
var1 = datetime();
var2 = datetime();
var3 = datetime();
format var1-var3 datetime19.;
run;
data want;
set have;
array allvars(*) var1-var3;
do i=1 to dim(allvars);
allvars(i) = datepart(allvars(i));
end;
format var1-var2 date9.;
drop i;
run;
Please remember that SAS has only two data types (numeric and character). Dates, times, and datetimes are only "known" as such when used with the appropriate format. In SAS:
- A date is the number of days since January 1, 1960
- A time is the number of seconds since midnight
- A datetime is the number of seconds since January 1, 1960.
And notice that date9.
is not a function; it is a format. There are a great many different formats that can be used to "exposed" the underlying value of the variable but the value itself does not change. That's one of the truly useful features of SAS programming.