I have a dataset with 200 character variables. all of those characters variables' lengths are between 5 to 10. Is there anyway to change the length of all of these character variables' to $40 in a short efficent way?( i know how to chnage the length or attribute, before the set statmment, but it will create a very long ugly coding)
Thank you a lot
I suppose you will need some codgen:
proc sql;
select name into :vname separated by ' ' from dictionary.columns where LIBNAME='SASHELP' AND MEMNAME='CLASS' AND type='char';
quit;
data want;
length &vname $ 40;
set sashelp.class;
run;
Haikuo
sorry did not understand how to relate your codes with my dataset.
proc sql;
select name into :vname separated by ' ' from dictionary.columns where LIBNAME='YOURLIB' /*NEED TO BE CAPPED*/ AND MEMNAME='YOURDATASET'/*NEED TO BE CAPPED*/ AND type='char';
quit;
data want;
length &vname $ 40;
set YOURLIB.YOURDATASET;
run;
Hi Hai,
Please find the log as below (bold and underlined) : SQL staement do not produce any rows. I am sure you are correct But i am missing something.
690 proc sql;
691 select name into :vname separated by ' ' from dictionary.columns where LIBNAME='YOURLIB'
691! /*NEED TO BE CAPPED*/ AND MEMNAME='YOURDATASET'/*NEED TO BE CAPPED*/ AND type='char';
NOTE: No rows were selected.
692 quit;
NOTE: PROCEDURE SQL used (Total process time):
real time 0.14 seconds
cpu time 0.01 seconds
693
694
695 data want;
696 length &vname $ 40;
697 set tto;
698 run;
NOTE: Variable Name is uninitialized.
NOTE: Variable Sex is uninitialized.
NOTE: There were 12 observations read from the data set WORK.TTO.
NOTE: The data set WORK.WANT has 12 observations and 26 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
proc sql;
select name into :vname separated by ' ' from dictionary.columns where LIBNAME='WORK' /*NEED TO BE CAPPED*/ AND MEMNAME='TTO'/*NEED TO BE CAPPED*/ AND type='char';
quit;
data want;
length &vname $ 40;
set TTO;
run;
Good luck,
Haikuo
Thanks Haikuo. It workd. Thanks a lot
HaiKuo's code will overwrite the table again , that would not be an efficient way .
data class; set sashelp.class; run; proc sql; select catx(' ',name,'char(40)') into :vname separated by ',' from dictionary.columns where LIBNAME='SASHELP' AND MEMNAME='CLASS' AND type='char'; alter table class modify &vname ; quit;
Xia Keshan
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.