CORE
mp_getmaxvarlengths.sas
Go to the documentation of this file.
1 
29 %macro mp_getmaxvarlengths(
30  libds /* libref.dataset to analyse */
31  ,outds=work.mp_getmaxvarlengths /* name of output dataset to create */
32 );
33 
34 %local vars x var fmt;
35 %let vars=%getvars(libds=&libds);
36 
37 proc sql;
38 create table &outds (rename=(
39  %do x=1 %to %sysfunc(countw(&vars,%str( )));
40  _&x=%scan(&vars,&x)
41  %end;
42  ))
43  as select
44  %do x=1 %to %sysfunc(countw(&vars,%str( )));
45  %let var=%scan(&vars,&x);
46  %if &x>1 %then ,;
47  %if %mf_getvartype(&libds,&var)=C %then %do;
48  max(length(&var)) as _&x
49  %end;
50  %else %do;
51  %let fmt=%mf_getvarformat(&libds,&var);
52  %put fmt=&fmt;
53  %if %str(&fmt)=%str() %then %do;
54  max(length(cats(&var))) as _&x
55  %end;
56  %else %do;
57  max(length(put(&var,&fmt))) as _&x
58  %end;
59  %end;
60  %end;
61  from &libds;
62 
63  proc transpose data=&outds
64  out=&outds(rename=(_name_=name COL1=ACTMAXLEN));
65  run;
66 
67 %mend;