DATA Step, Macro, Functions and more

Disallowed combinations

Reply
New Contributor L
New Contributor
Posts: 2

Disallowed combinations

I am trying to use the mktkey and mktroll macros to create a choice experiment. Within this choice experiment, I need to create disallowed combinations. The experiment has three factors, each with seven levels. The seven levels within each factor are identical, and I need to unable them to repeat within a choice set. Essentially, I have varying combinations of three out of the seven levels. However, I am having trouble setting up the disallowed combinations. Does anyone have any advice for how to code those disallowed combinations?
Regular Contributor
Posts: 165

Re: Disallowed combinations

I don't believe those are macros that are shipped with SAS. Can you post the code for these macros? We would then be able to help you out more easily.
New Contributor L
New Contributor
Posts: 2

Re: Disallowed combinations

Mktkey macro:
/****************************************************************/
/* S A S A U T O C A L L L I B R A R Y */
/* */
/* NAME: MktKey */
/* TITLE: Create Variables Lists for MktRoll */
/* PRODUCT: STAT */
/* SYSTEM: ALL */
/* KEYS: marketing research, designs */
/* PROCS: */
/* DATA: */
/* SUPPORT: saswfk UPDATE: 25Jul2010 */
/* REF: See "Marketing Research Methods in SAS" at the */
/* following URL for more information on this macro. */
/* */
/* http://support.sas.com/techsup/tnote/tnote_stat.html#market */
/* */
/* MISC: The following SAS products are required to run */
/* this macro: BASE. */
/* */
/* This macro creates global macro variables: _MktVer */
/****************************************************************/

/*---------------------------------------------------------------------

If you will be using the MktRoll macro to make a choice design from the
linear design that MktEx produces, you can call MktKey macro to get all
of the variable names. For example,

%mktkey(3 5)

produces a 3x5 matrix of the names x1-x15:

x1 x2 x3 x4 x5

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

which can be cut and pasted into a program like this to make the choice
design:

data key;
input (Brand Price Size Color Shape Form) ($);
datalines;
A x1 x2 x3 x4 x5
B x6 x7 x8 x9 x10
C x11 x12 x13 x14 x15
None . . . . .
;

%mktroll(key=key, design=randomized, out=choicedes, alt=brand)

There are three forms of input the the macro:

* A number of rows followed by a number of columns, as in the example above.
The output is a data set called KEY with row * column variable names,
x1, x2, ....
* A number of rows followed by a number of columns followed by "t" or "T"
for transpose. The output data set called KEY is as follows.
%mktkey(6 4 t)

x1 x2 x3 x4

x1 x7 x13 x19
x2 x8 x14 x20
x3 x9 x15 x21
x4 x10 x16 x22
x5 x11 x17 x23
x6 x12 x18 x24

This is the transpose of the default data set with variable names
progressing down the columns rather than across the rows.

* A variable list.
%mktkey(x1-x20)
The expanded variable list is printed to the log and no data set
is created:
x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15 x16 x17 x18 x19 x20

------------------------------------------------------------------------

DISCLAIMER:

THIS INFORMATION IS PROVIDED BY SAS INSTITUTE INC. AS A SERVICE
TO ITS USERS. IT IS PROVIDED "AS IS". THERE ARE NO WARRANTIES,
EXPRESSED OR IMPLIED, AS TO MERCHANTABILITY OR FITNESS FOR A
PARTICULAR PURPOSE REGARDING THE ACCURACY OF THE MATERIALS OR CODE
CONTAINED HEREIN.

----------------------------------------------------------------------*/

%macro mktkey( /*--------------------------------------------------*/
list /* rows columns - x1-x(rows x columns) */
/* rows columns t - x1-x(rowx x columns) transposed */
/* variable list - expands list */
/* ? or help - lists options */
); /*--------------------------------------------------*/

;*=========================== Macro Start =============================;

*------initial macro stuff------;
%global _MktVer;
%local localver abort k r c b savenote setnote timeopt;

%let localver = 25Jul2010;
%let timeopt = %scan(STIMER STATS, 1 + (&sysscp = OS));
%let savenote = %sysfunc(getoption(&timeopt)) %sysfunc(getoption(notes));
%let setnote = nonotes no&timeopt;
%let _mktver = &localver;
%let abort = 0;

options noserror;
%if %nrquote(&&mktopts) ne %nrstr(&)mktopts %then %do;
%let k = %upcase(&mktopts);
%if %index(&k, CHECKVERSION) %then %do; options serror; %goto mendit; %end;
%if %index(&k, NOTES) %then %let setnote = notes &timeopt;
%if %index(&k, VERSION) %then %put MktKey macro version &localver.;
%end;
options serror;

options &setnote;

data _null_;
length list $ 32;
list = left(lowcase(symget('list')));
if list eq 'help' or list eq '?' then call symput('abort', '-1');
if _error_ then call symput('abort', '1');
run;

%if &syserr > 4 %then %let abort = 1; %if &abort = 1 %then %goto endit;

%if &abort = -1 %then %do; %let abort = 0; %mkthelp(mktkey) %goto endit; %end;

data _null_;
length str $ 200;
str = symget('list');
if str = ' ' then do;
put 'ERROR: You must specify the LIST positional parameter.';
call symput('abort', '1');
end;

r = input(scan(str, 1, ' '), ?? 23.);
if n(r) then do;
call symput('r', compress(put(r, 5.)));
c = input(scan(str, 2, ' '), ?? 23.);
if n(c) then do;
call symput('c', compress(put(c, 5.)));
if scan(str, 3, ' ') in ('t', 'T') then b = r;
else b = 1;
call symput('b', compress(put(b, 5.)));
end;
else do;
put 'ERROR: Either specify a variable list or a row and column.';
call symput('abort', '1');
end;
end;
if _error_ then call symput('abort', '1');
run;

%if &syserr > 4 %then %let abort = 1; %if &abort %then %goto endit;

%if %nrbquote(&r) ne %then %do;

data key(keep=x1-x&c);
array x
  • $ x1-x&c;
    do b = 1 to &b;
    do i = b to %eval(&r * &c) by &b;
    k + 1;
    x = compress('x' || put(i, 5.));
    if k = &c then do; output; k = 0; end;
    end;
    end;
    if _error_ then call symput('abort', '1');
    run;

    %if &syserr > 4 %then %let abort = 1; %if &abort %then %goto endit;

    proc print noobs; run;

    %if &syserr > 4 %then %let abort = 1; %if &abort %then %goto endit;
    %end;

    %else %do;

    data _null_;
    length __name $ 32;
    array __x
  • &list;
    do __i = 1 to dim(__x);
    call vname(__x[__i], __name);
    put __name @@;
    end;
    if _error_ then call symput('abort', '1');
    run;

    %if &syserr > 4 %then %let abort = 1; %if &abort %then %goto endit;
    %end;

    %endit: options &savenote;
    quit;

    %if &abort %then %put ERROR: The MKTKEY macro ended abnormally.;

    %mendit: %mend;

    Mktroll macro:
    /****************************************************************/
    /* S A S A U T O C A L L L I B R A R Y */
    /* */
    /* NAME: MktKey */
    /* TITLE: Create Variables Lists for MktRoll */
    /* PRODUCT: STAT */
    /* SYSTEM: ALL */
    /* KEYS: marketing research, designs */
    /* PROCS: */
    /* DATA: */
    /* SUPPORT: saswfk UPDATE: 25Jul2010 */
    /* REF: See "Marketing Research Methods in SAS" at the */
    /* following URL for more information on this macro. */
    /* */
    /* http://support.sas.com/techsup/tnote/tnote_stat.html#market */
    /* */
    /* MISC: The following SAS products are required to run */
    /* this macro: BASE. */
    /* */
    /* This macro creates global macro variables: _MktVer */
    /****************************************************************/

    /*---------------------------------------------------------------------

    If you will be using the MktRoll macro to make a choice design from the
    linear design that MktEx produces, you can call MktKey macro to get all
    of the variable names. For example,

    %mktkey(3 5)

    produces a 3x5 matrix of the names x1-x15:

    x1 x2 x3 x4 x5

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

    which can be cut and pasted into a program like this to make the choice
    design:

    data key;
    input (Brand Price Size Color Shape Form) ($);
    datalines;
    A x1 x2 x3 x4 x5
    B x6 x7 x8 x9 x10
    C x11 x12 x13 x14 x15
    None . . . . .
    ;

    %mktroll(key=key, design=randomized, out=choicedes, alt=brand)

    There are three forms of input the the macro:

    * A number of rows followed by a number of columns, as in the example above.
    The output is a data set called KEY with row * column variable names,
    x1, x2, ....
    * A number of rows followed by a number of columns followed by "t" or "T"
    for transpose. The output data set called KEY is as follows.
    %mktkey(6 4 t)

    x1 x2 x3 x4

    x1 x7 x13 x19
    x2 x8 x14 x20
    x3 x9 x15 x21
    x4 x10 x16 x22
    x5 x11 x17 x23
    x6 x12 x18 x24

    This is the transpose of the default data set with variable names
    progressing down the columns rather than across the rows.

    * A variable list.
    %mktkey(x1-x20)
    The expanded variable list is printed to the log and no data set
    is created:
    x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15 x16 x17 x18 x19 x20

    ------------------------------------------------------------------------

    DISCLAIMER:

    THIS INFORMATION IS PROVIDED BY SAS INSTITUTE INC. AS A SERVICE
    TO ITS USERS. IT IS PROVIDED "AS IS". THERE ARE NO WARRANTIES,
    EXPRESSED OR IMPLIED, AS TO MERCHANTABILITY OR FITNESS FOR A
    PARTICULAR PURPOSE REGARDING THE ACCURACY OF THE MATERIALS OR CODE
    CONTAINED HEREIN.

    ----------------------------------------------------------------------*/

    %macro mktkey( /*--------------------------------------------------*/
    list /* rows columns - x1-x(rows x columns) */
    /* rows columns t - x1-x(rowx x columns) transposed */
    /* variable list - expands list */
    /* ? or help - lists options */
    ); /*--------------------------------------------------*/

    ;*=========================== Macro Start =============================;

    *------initial macro stuff------;
    %global _MktVer;
    %local localver abort k r c b savenote setnote timeopt;

    %let localver = 25Jul2010;
    %let timeopt = %scan(STIMER STATS, 1 + (&sysscp = OS));
    %let savenote = %sysfunc(getoption(&timeopt)) %sysfunc(getoption(notes));
    %let setnote = nonotes no&timeopt;
    %let _mktver = &localver;
    %let abort = 0;

    options noserror;
    %if %nrquote(&&mktopts) ne %nrstr(&)mktopts %then %do;
    %let k = %upcase(&mktopts);
    %if %index(&k, CHECKVERSION) %then %do; options serror; %goto mendit; %end;
    %if %index(&k, NOTES) %then %let setnote = notes &timeopt;
    %if %index(&k, VERSION) %then %put MktKey macro version &localver.;
    %end;
    options serror;

    options &setnote;

    data _null_;
    length list $ 32;
    list = left(lowcase(symget('list')));
    if list eq 'help' or list eq '?' then call symput('abort', '-1');
    if _error_ then call symput('abort', '1');
    run;

    %if &syserr > 4 %then %let abort = 1; %if &abort = 1 %then %goto endit;

    %if &abort = -1 %then %do; %let abort = 0; %mkthelp(mktkey) %goto endit; %end;

    data _null_;
    length str $ 200;
    str = symget('list');
    if str = ' ' then do;
    put 'ERROR: You must specify the LIST positional parameter.';
    call symput('abort', '1');
    end;

    r = input(scan(str, 1, ' '), ?? 23.);
    if n(r) then do;
    call symput('r', compress(put(r, 5.)));
    c = input(scan(str, 2, ' '), ?? 23.);
    if n(c) then do;
    call symput('c', compress(put(c, 5.)));
    if scan(str, 3, ' ') in ('t', 'T') then b = r;
    else b = 1;
    call symput('b', compress(put(b, 5.)));
    end;
    else do;
    put 'ERROR: Either specify a variable list or a row and column.';
    call symput('abort', '1');
    end;
    end;
    if _error_ then call symput('abort', '1');
    run;

    %if &syserr > 4 %then %let abort = 1; %if &abort %then %goto endit;

    %if %nrbquote(&r) ne %then %do;

    data key(keep=x1-x&c);
    array x
  • $ x1-x&c;
    do b = 1 to &b;
    do i = b to %eval(&r * &c) by &b;
    k + 1;
    x = compress('x' || put(i, 5.));
    if k = &c then do; output; k = 0; end;
    end;
    end;
    if _error_ then call symput('abort', '1');
    run;

    %if &syserr > 4 %then %let abort = 1; %if &abort %then %goto endit;

    proc print noobs; run;

    %if &syserr > 4 %then %let abort = 1; %if &abort %then %goto endit;
    %end;

    %else %do;

    data _null_;
    length __name $ 32;
    array __x
  • &list;
    do __i = 1 to dim(__x);
    call vname(__x[__i], __name);
    put __name @@;
    end;
    if _error_ then call symput('abort', '1');
    run;

    %if &syserr > 4 %then %let abort = 1; %if &abort %then %goto endit;
    %end;

    %endit: options &savenote;
    quit;

    %if &abort %then %put ERROR: The MKTKEY macro ended abnormally.;

    %mendit: %mend;

    Though, I thought I could invoke the macro as is with %mktkey and %mktroll, then make the disallowed combinations in the editor window. Is that not right? Do I change the macro itself?
  • Trusted Advisor
    Posts: 2,116

    Re: Disallowed combinations

    Though I don't know the answer to L's question, the macros are described in

    http://support.sas.com/techsup/technote/mr2010.pdf
    SAS Super FREQ
    Posts: 8,866

    Re: Disallowed combinations

    Hi:
    On page 25 of this document (about mktkey and mktroll and other Marketing Research macros), http://support.sas.com/techsup/technote/mr2010.pdf
    it says:
    "SAS Technical Support can help you if you encounter a problem or issue while working with the market research design macros..."

    To open a track with Tech Support, fill out the form at this link:
    http://support.sas.com/ctx/supportform/createForm

    cynthia
    Ask a Question
    Discussion stats
    • 4 replies
    • 189 views
    • 0 likes
    • 4 in conversation