Since your second step (DATA Step) recreates the original data, you could simply use a LENGTH statement before the SET statement to increase the length of a variable. To me your code looks correct.
Try the code below for a sample program using SASHELP.CLASS
proc sql;
create table newclass as
select * from sashelp.class
;
alter table newClass
modify name char(20)
;
quit;
data want;
set newclass;
if sex = "M" then do;
name = catx(":", "CHG", name, sex, age);
end;
run;
data want2;
length name $ 20;
set sashelp.class;
if sex = "M" then do;
name = catx(":", "CHG", name, sex, age);
end;
run;
Bruno
Editor's note: As suggested by @Ksharp, a character variable format can cause only a few of the available characters to display, even if the length has been changed successfully. Always check the metadata for actual length after modifying a table. For example:
data work.cars_data_step_length
work.cars_sql_modify;
/* Use LENGTH before SET to change length */
length Make $200;
set sashelp.cars (obs=5);
run;
proc sql;
/* Use ALTER TABLE / MODIFY to change length */
alter table work.cars_sql_modify
modify Make char(100)
;
title "Final Variable Lengths ";
select catx('.',libname,Memname) as Table, Name, Type, Length
from dictionary.columns
where memname like 'CARS%'
and libname in ('SASHELP','WORK')
and Name='Make';
quit;
For information about removing unwanted formats, resizing, and renaming table columns, see the SAS Tutorial "Resize, Rename and Reformat Data with SAS Macros".
... View more