If your original data already has some numeric columns you probably want to retain the original column order in your new data set.
This version of the conversion approach uses code generation that explicitly codes the INPUT transform for each character variable (no array in the DATA Step). This can have a minor performance improvement because all the 'array' computations are done at step compilation time instead of at step runtime, the downside being that the convert codegen can exceed 64k bytes if the original data set has several thousand character columns.
Also, if your character column names are very long (28-32 long) some renaming schemes for the worker variable involving the original column name could exceed 32 char and cause compile time error.
This example retains original column order and uses a shorter working variable name (__<varnum>)
data have;
array x[10] (1:10);
array s[10] $20 ('10', '9', '8.8', '777', '666', '55', '4', '3.14159', '2','1.000001') ;
run;
proc contents noprint data=have out=have_meta;
run;
proc sql noprint;
select
case when type=2 then cats(name,'=__',varnum) else '' end,
case when type=2 then cats(name,'= input(__',varnum,',32.);') else '' end,
case when type=2 then cats('__',varnum) else '' end,
name
into
:rename separated by ' ',
:convert separated by ';',
:drop separated by ' ',
:all_columns separated by ' '
from have_meta
order by varnum
;
quit;
options symbolgen;
data want(drop=&drop);
retain &all_columns;
set have (rename=(&rename));
&convert;
run;
... View more