BookmarkSubscribeRSS Feed
need_sas_help
Calcite | Level 5

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

7 REPLIES 7
Haikuo
Onyx | Level 15

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

need_sas_help
Calcite | Level 5

sorry did not understand how to relate your codes with my dataset.

Haikuo
Onyx | Level 15

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;

need_sas_help
Calcite | Level 5

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

Haikuo
Onyx | Level 15

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

need_sas_help
Calcite | Level 5

Thanks Haikuo. It workd. Thanks a lot

Ksharp
Super User

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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 6315 views
  • 0 likes
  • 3 in conversation