Unfortunately there is no way to do this without reading through the data twice - once to determine lengths, and once to apply them:
filename tmp temp;
data _null_;
set have end=eod;
array chrvar {*} $1000 _character_;
array len{1000} _temporary_;
do c=1 to dim(chrvar);
len{c}=max(len{c},length(chrvar{c}));
end;
file tmp;
if eod then do c=1 to dim(chrvar);
vnam=vname(chrvar{c});
put vnam '$' len{c};
end;
run;
options source2;
data want;
length %include tmp ;;
set have;
run;
Notes
The filename tmp has file type TEMP, for temporary. It'll be automatically deleted at the end of your sas session.
I assigned a varlength of $1000 to array charvar, since that's what you said they are.
For array LEN, assign an array count you know is larger than the number of character variables.
The "file tmp" statement tells SAS where the put statement will write.
In the second data step, the LENGTH statement ends with two semi-colons: one to terminate the %include statement, and one to teminate the length statement. (the options source2 statement will print everything from the %include on the log).
... View more