As the first step in the decommissioning of the site has been converted to read-only mode.

Here are some tips for How to share your SAS knowledge with your professional network.

Tips:Using Multilabel Formats to Expand or Duplicate Data

From sasCommunity
Revision as of 21:01, 22 June 2015 by Frankfry (Talk | contribs)

Jump to: navigation, search
proc format;
value age (multilabel notsorted)
  /* 14='14' */ /* values not in the format are excluded from the output */
  /* 16='16' */ /* values not in the format are excluded from the output */
proc summary data=sashelp.class nway;
class name age/mlf;
id sex height weight;
format age age.;
output out=expanded(drop=_type_ _freq_);

Multivalue formats as illustrated in this PROC REPORT example can be quite useful to create reports with multiple overlapping groups. But only a few procedures support such formats.

However you can trick it by using a multivalue format to expand a data creating duplicate rows. This can be useful if you want to run other procedures like PROC UNIVARIATE or do other calculations like counting unique occurrences.

The code at the right illustrates a way to use multilabel formats to create duplicate rows for later analysis. This can be a nice alternative to writing your own code to do, for example, Cartesian products.

The basic idea is to run PROC SUMMARY with the NWAY option where one of the class variables uniquely identifies each input row. In this example, we want to associate each age value with multiple groups. In this case, the variable name uniquely identifies each observation and multiple output observations are created for each of assigned values of age in the format. Since no VAR statement is included, the observations are output/duplicated as is.

  • for each input observation, the output data set has 0 or more output rows with the values defined for age in the format.
  • note that excluding a value from the format results in no output rows.

....see also

Submitted By Don Henderson (talk)