BookmarkSubscribeRSS Feed
L
Calcite | Level 5 L
Calcite | Level 5
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?
4 REPLIES 4
RickM
Fluorite | Level 6
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.
L
Calcite | Level 5 L
Calcite | Level 5
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?
  • Doc_Duke
    Rhodochrosite | Level 12
    Though I don't know the answer to L's question, the macros are described in

    http://support.sas.com/techsup/technote/mr2010.pdf
    Cynthia_sas
    SAS Super FREQ
    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

    sas-innovate-2024.png

    Available on demand!

    Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

     

    Register now!

    How to Concatenate Values

    Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

    Find more tutorials on the SAS Users YouTube channel.

    Click image to register for webinarClick image to register for webinar

    Classroom Training Available!

    Select SAS Training centers are offering in-person courses. View upcoming courses for:

    View all other training opportunities.

    Discussion stats
    • 4 replies
    • 905 views
    • 0 likes
    • 4 in conversation