This program seems overly complicated and i can't really figure out what it does by just reading it.
If the goal is just to modify the length of character columns to the minimal length that avoids truncation,
you can try the following macro :
%macro resize(lib=sashelp, mem=class, out=&mem.);
proc sql noprint;
/* We get the list of charcter columns */
SELECT NAME
INTO :CHARCOLS SEPARATED BY ' '
FROM dictionary.columns
WHERE LIBNAME=upcase("&lib.") AND MEMNAME=upcase("&mem.")
AND upcase(TYPE)="CHAR";
/* For each char column we get the minimum length that avoids truncation */
/* Ex: "var1 $5. var2 $7. ..." */
%let nchars=%sysfunc(countw(&CHARCOLS));
SELECT DISTINCT cat(
%do i=1 %to &nchars.;
%let col=%scan(&CHARCOLS.,&i.,' ');
" &col. $",max(length(&col.)),".",
%end;
"") /* "" for the last comma */
INTO :lengths SEPARATED BY ' '
FROM &lib..&mem.;
quit;
/* New dataset with resized char columns */
data &out.;
length &lengths.;
set &lib..&mem.;
run;
%mend resize;
%resize;
... View more