FOCUS AREAS


Contents | SAS Program | PDF

The %MktKey Macro

Introduction

The %MktKey autocall macro creates expanded lists of variable names and creates an output data set named Key. This macro is most commonly used to create KEY= input data sets for the %MktRoll macro.

%MktKey Macro Syntax

%MktKey ( list )

Required Argument

list

specifies the variable list or matrix size list, optionally followed by a t or T (for transpose). The list is a positional argument and it is not specified after a name and an equal sign. Without the t, the names go X1, X2, X3, and so on, across each row. With the t, the names go X1, X2, X3, and so on, down each column.

Help Option

You can specify either of the following to display the option names and simple examples of the macro syntax:

%mktkey(help)
%mktkey(?)

Example

This example uses the %MktKey macro to create a key data set for that contains 5 rows and 10 columns and $5\times 10 = 50$ variable names, X1X50. You can specify the number of rows followed by the number of columns as follows:

%mktkey(5 10)

Figure 1 shows the resulting Key output data set.

Figure 1: %MktKey(5 10) Data Set

x1 x2 x3 x4 x5 x6 x7 x8 x9 x10
x1 x2 x3 x4 x5 x6 x7 x8 x9 x10
x11 x12 x13 x14 x15 x16 x17 x18 x19 x20
x21 x22 x23 x24 x25 x26 x27 x28 x29 x30
x31 x32 x33 x34 x35 x36 x37 x38 x39 x40
x41 x42 x43 x44 x45 x46 x47 x48 x49 x50


Alternatively, you can specify the number of rows and number of columns followed by a t or T and get the transpose of this data set. The output data set is again called Key. The following statement demonstrates this option:

%mktkey(5 10 t)

Figure 2 shows the resulting Key output data set. This time the names progress down the columns instead of across the rows.

Figure 2: %MktKey(5 10 t) Transposed Data Set

x1 x2 x3 x4 x5 x6 x7 x8 x9 x10
x1 x6 x11 x16 x21 x26 x31 x36 x41 x46
x2 x7 x12 x17 x22 x27 x32 x37 x42 x47
x3 x8 x13 x18 x23 x28 x33 x38 x43 x48
x4 x9 x14 x19 x24 x29 x34 x39 x44 x49
x5 x10 x15 x20 x25 x30 x35 x40 x45 x50


The %MktKey macro also has another type of syntax. You can provide a list of variables to the %MktKey macro as follows:

%mktkey(x1-x15)

The %MktKey macro produces the following line in your SAS log:

x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15

You can copy and paste this list to make it easier to construct the KEY= data set for the %MktRoll macro. The following statements create the Key data set:

data key;
   input (x1-x5) ($);
   datalines;
 x1  x2  x3  x4  x5
 x6  x7  x8  x9 x10
x11 x12 x13 x14 x15
  .   .   .   .   .
;