Revision as of 21:05, 22 June 2015

proc format;
value age (multilabel notsorted)11='11'12='12'11-12='Pre-Teen'13='13'/* 14='14' *//* values not in the format are excluded from the output */15='15'/* 16='16' *//* values not in the format are excluded from the output */13-16='Teen'11-16='All';
run;
proc summarydata=sashelp.class nway;
class name age/mlf;
id sex height weight;
format age age.;
output out=expanded(drop=_type_ _freq_);
run;

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.