I usually avoid trying to loop through observations and instead apply SAS operations to full sets. You can pull the metadata for your original file and use it to generate the new variables. You can view your conversion step as this simple data step. data want; &attrib; array _char $32 &oldchar ; array _num &newnum; set have (rename=(&rename)) ; do over _char; _num=input(_char,best32.); end; drop &oldchar ; run; Where ATTRIB contains a series of ATTRIB statements to set the variables names, type, length, format, label etc . RENAME contains old=newname pairs that will rename the old character variables to unique temporary names so that new numeric variables with those names can be created. OLDCHAR contain the renamed character variables that need to be converted to numeric. NEWNUM contain the names of the variables to convert from numeric to character. For example if you want to convert all character variables to numeric then you can generate those four list variables with something like: proc sql noprint ; create table vardef as select * from dictionary.columns where libname='WORK' and memname='A' ; select catx(' ','attrib',name,'length=8','label=',quote(trim(label)||' ')) , varnum into :attrib separated by ';' , :dummy from vardef order by varnum ; select name , catx('=',name,'_'||name) , '_'||name into :newnum separated by ' ' , :rename separated by ' ' , :oldchar separated by ' ' from vardef ; quit; For a more complicated situation you might need to use more complicated queries to generate ATTRIB (especially for length and format attributes) or to subset the variables included in the other three macro variables.
... View more