There are many ways to do this, but since the formatting information is stored in SASHELP.VCOLUMN, I think it is easier to store it in a macro variable and have it processed.
data have;
format x1 z6.
x2 date9.
x3 dollar12.2
x4 time5.
x5 datetime16.;
array x{5};
do i=1 to 5;
x{i}=10000;
end;
drop i;
run;
data _null_;
set sashelp.vcolumn;
where libname='WORK' and memname='HAVE';
call symputx(cats('fmt',_n_),format);/* format to macro variable */
call symputx(cats('name',_n_),name);/* variable name to macro variable */
call symputx('nobs',_n_);/* loop count */
run;
%Macro Mtransform;
data want;
set have;
length char1-char5 $200;
%do i=1 %to &nobs;
char&i=putn(&&name&i,"&&fmt&i");
%end;
run;
%Mend;
%Mtransform;
... View more