Date: Sat, 4 Nov 2006 13:17:32 -0800
Reply-To: d5p@HOTMAIL.CO.UK
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: d5p@HOTMAIL.CO.UK
Organization: http://groups.google.com
Subject: Re: Re-formating variables
Content-Type: text/plain; charset="iso-8859-1"
You could always grab a list of the variables and loop through it using
the input function to convert. Although not sure how quickly will run
on large datasets.
Below is example code for this (this is just a quick suggestion there
may well be more elegant ways of coding this...).
/*a test dataset with the character variables*/
data test(drop=i);
do i=1 to 100;
l3="43";
l4="45";
output;
end;
run;
/*grab a list of all the character vars*/
proc sql noprint;
select name into : varz separated by ' '
from dictionary.columns
where memname="TEST" and type='char';
quit;
/*rename all those character vars*/
%macro rename();
%let i=0;
%do %while(%scan(&varz,&i+1,%str( )) ne %str( ));
%let i = %eval(&i+1);
%let var = %scan(&varz,&i,%str( ));
rename &var = d_&var;
%end;
%mend rename;
proc datasets library=work;
modify test;
%rename;
quit;
/*grab a list of all the renamed character vars*/
proc sql noprint;
select name into : varz2 separated by ' '
from dictionary.columns
where memname="TEST" and type='char';
quit;
/*change the format of those variables*/
%macro chgformat();
%let i=0;
%do %while(%scan(&varz,&i+1,%str( )) ne %str( ));
%let i = %eval(&i+1);
%let var = %scan(&varz,&i,%str( ));
&var = input(d_&var,8.);
%end;
%mend chgformat;
data test2(drop=&varz2);
set test;
%chgformat;
run;