Macros for SAS Application Developers
https://github.com/sasjs/core
mp_applyformats.sas File Reference

Apply a set of formats to a table. More...

Go to the source code of this file.

Detailed Description

Applies a set of formats to the metadata of one or more SAS datasets. Can be used to migrate formats from one table to another. The input table must contain the following columns:

  • lib - the libref of the table to be updated
  • ds - the dataset to be updated
  • var - the variable to be updated
  • fmt - the format to apply. Missing or default ($CHAR, 8.) formats are ignored.

The macro will abort in the following scenarios:

  • Libref not assigned
  • Dataset does not exist
  • Input table contains null or invalid values

Example usage:

data work.example;
  set sashelp.prdsale;
  format _all_ clear;
run;

%mp_getcols(sashelp.prdsale,outds=work.cols)

data work.cols2;
  set work.cols;
  lib='WORK';
  ds='EXAMPLE';
  var=name;
  fmt=format;
  keep lib ds var fmt;
run;

%mp_applyformats(work.cols2)
Parameters
[in]indsThe input dataset containing the formats to apply (and where to apply them). Example structure:
LIB:$8. DS:$32. VAR:$32. FMT:$49.
WORK EXAMPLE ACTUAL DOLLAR12.2
WORK EXAMPLE COUNTRY $CHAR10.
WORK EXAMPLE DIVISION $CHAR10.
WORK EXAMPLE MONTH MONNAME3.
WORK EXAMPLE PREDICT DOLLAR12.2
WORK EXAMPLE PRODTYPE $CHAR10.
WORK EXAMPLE PRODUCT $CHAR10.
WORK EXAMPLE QUARTER 8.
WORK EXAMPLE REGION $CHAR10.
WORK EXAMPLE YEAR 8.
[out]errds=(0) Provide a libds reference here to export the error messages to a table. In this case, they will not be printed to the log.

SAS Macros

Related Macros

Version
9.2
Author
Allan Bowe

Definition in file mp_applyformats.sas.