combine Combine the values of two or more variables combine

SAS Macro Programs: combine

$Version: 1.1-1 (09 Feb 2006)
Michael Friendly
York University


The combine macro ( [download] get combine.sas)

Combine the values of two or more variables

The COMBINE macro combines two or more variables (character or numeric) into a single one. This is useful for situations where you need two or more CLASS variables, but some procedure or macro stupidly only handles one. Also handy for plots of the form

  plot y * x = Group Sex

where there are two or more curve variables.

Usage

The COMBINE macro is called with keyword parameters. The VAR= parameter is required. The arguments may be listed within parentheses in any order, separated by commas. For example:

  %combine(var=group gender, result=gp_sex);

Parameters

DATA=
The name of the input data set [Default: DATA=_LAST_]
VAR=
List of two or more variables to be combined. *required*
RESULT=
The name of the result variable. [Default: RESULT=_ID_]
WHERE=
Otional WHERE clause to subset the observations written to the OUT= data set.
SEP=
Separator character(s), inserted between adjacent values [Default: SEP=:]
ABBREV=
If specified, each character variable in VAR= is truncated to this length in RESULT. To specify different truncation lengths, use a list of numbers, whose order corresponds to the VAR= variables, e.g., ABBREV=2 2 4.
LENGTH=
If specified, the RESULT= variable is truncated to this total length, regardless of the ABBREV= setting.
USEFMT=
If postive, numeric variables which have formats stored in the data set have their formatted values combined. [Default: USEFMT=0]
IGNMISS=
Ignore missing values?
OUT=
The name of the output data set. The default (OUT=&data) means that the input data set is replaced. [Default: OUT=&data]

Bugs

The internally calculated length for the result variable is incorrect for numeric variables.

Should provide a way to use a formatted value of a character variable.

Example

%include macros(combine);        *-- or include in an autocall library;

data design;
   do task =  'EASY', 'HARD';
      do dose = ., 0 to 2;
         output;
         end;
      end;

%combine(data=design, var=task dose, out=test);
proc print;
Obs    task    dose     _id_

 1     EASY      .     EASY:.
 2     EASY      0     EASY:0
 3     EASY      1     EASY:1
 4     EASY      2     EASY:2
 5     HARD      .     HARD:.
 6     HARD      0     HARD:0
 7     HARD      1     HARD:1
 8     HARD      2     HARD:2

See also