Macros for SAS Application Developers
https://github.com/sasjs/core
Loading...
Searching...
No Matches
mp_getmaxvarlengths.sas File Reference

Scans a dataset to find the max length of the variable values. More...

Go to the source code of this file.

Detailed Description

This macro will scan a base dataset and produce an output dataset with two columns:

  • NAME Name of the base dataset column
  • MAXLEN Maximum length of the data contained therein.

Character fields are often allocated very large widths (eg 32000) of which the maximum value is likely to be much narrower. Identifying such cases can be helpful in the following scenarios:

  • Enabling a HTML table to be appropriately sized (num2char=YES)
  • Reducing the size of a dataset to save on storage (mp_ds2squeeze.sas)
  • Identifying columns containing nothing but missing values (MAXLEN=0 in the output table)

If the entire column is made up of (non-special) missing values then a value of 0 is returned.

Usage:

%mp_getmaxvarlengths(sashelp.class,outds=work.myds)
Parameters
[in]libdsTwo part dataset (or view) reference.
[in]num2char=(NO) When set to NO, numeric fields are sized according to the number of bytes used (or set to zero in the case of non-special missings). When YES, the numeric field is converted to character (using the format, if available), and that is sized instead, using lengthn().
[out]outds=The output dataset to create, eg:
NAME:$8. MAXLEN:best.
Name 7
Sex 1
Age 3
Height 8
Weight 3

SAS Macros

Version
9.2
Author
Allan Bowe

Related Macros

Definition in file mp_getmaxvarlengths.sas.