Hello everyone,
I'm currently working on a code that aims to create choice sets. I try to reduce the number of choice sets, but I'm encountering an error message and I'm unsure how to resolve it. My goal is to reduce the choice sets to 10, but the code is not functioning as expected, while it works for 18 choice sets.
Here is the relevant code snippet:
title ’WTP’; %mktruns(17 2 2 2 2) %mktex(17 2 2 2 2, n=68, seed = 70) %macro res3; x1 = x[1,1]; x2 = x[1,2]; x3 = x[1,3]; x4 = x[1,4]; x5 = x[1,5]; x6 = x[2,1]; x7 = x[2,2]; x8 = x[2,3]; x9 = x[2,4]; x10 = x[2,5]; x11 = x[3,1]; x12 = x[3,2]; x13 = x[3,3]; x14 = x[3,4]; x15 = x[3,5]; x16 = x[4,1]; x17 = x[4,2]; x18 = x[4,3]; x19 = x[4,4]; x20 = x[4,5]; c1 = x2 + x3 + x4 + x5; c2 = x7 + x8 + x9 + x10; c3 = x12 + x13 + x14 + x15; c4 = x17 + x18 + x19 +x20; if c1 < c2 & x1 >= x6 then bad = 1; if c2 < c1 & x6 >= x1 then bad = bad + 1; if c2 < c3 & x6 >= x11 then bad = bad + 1; if c3 < c2 & x11 >= x6 then bad = bad + 1; if c1 < c3 & x1 >= x11 then bad = bad + 1; if c3 < c1 & x11 >= x1 then bad = bad + 1; if c1 < c4 & x1 >= x16 then bad = 1 + 1; if c4 < c1 & x16 >= x1 then bad = bad + 1; if c2 < c4 & x6 >= x16 then bad = bad + 1; if c4 < c2 & x16 >= x6 then bad = bad + 1; if c4 < c3 & x16 >= x11 then bad = bad + 1; if c3 < c4 & x11 >= x16 then bad = bad + 1; /*if x1 = x5 | x1 = x9 | x5=x9 then bad = bad + 1;*/ if x2 = x7 & x3 = x8 & x4 = x9 & x5 = x10 then bad = bad + 1; if x2 = x12 & x3 = x13 & x4 = x14 & x5 = x15 then bad = bad + 1; if x2 = x17 & x3 = x18 & x4 = x19 & x5 = x20 then bad = bad + 1; if x7 = x12 & x8 = x13 & x9 = x14 & x10 = x15 then bad = bad + 1; if x7 = x17 & x8 = x18 & x9 = x19 & x10 = x20 then bad = bad + 1; if x2 = 1 & x3 = 1 & x4 = 1 & x5 = 1 then bad = bad + 1; if x7 = 1 & x8 = 1 & x9 = 1 & x10 = 1 then bad = bad + 1; if x12 = 1 & x13 = 1 & x14 = 1 & x15 = 1 then bad = bad + 1; if x17 = 1 & x18 = 1 & x19 = 1 & x20 = 1 then bad = bad + 1; %mend; %choiceff(data=randomized, /* candidate set of alternatives */ model=class(x1-x5 / sta), /* model with stdzd orthogonal coding */ nsets=10, /* number of choice sets */ seed=70, /* random number seed */ flags=4, /* 4 alternatives, generic candidates */ options=relative nodups, /* display relative D-efficiency */ beta=zero, restrictions=res3, resvars=x1-x5, maxiter=50, bestout=desres2) /* assumed beta vector, Ho: b=0 */ proc print data=desres2; id set; by set; var x:; run; %mktdups(generic, data=desres2, factors=x1-x5, nalts=4) proc format; value price 1=0.25 2=0.50 3=0.75 4=1.00 5=1.25 6=1.50 7=1.75 8=2.00 9=2.25 10=2.50 11=2.75 12=3.00 13=3.25 14=3.50 15=3.75 16=4.00 17=4.25; value location 1="no" 2="yes"; value financial 1="no" 2="yes"; value health 1="no" 2="yes"; value browsinghistory 1="no" 2="yes"; run; data desres2; set desres2; format x1 price. x2 location. x3 financial. x4 health. x5 browsinghistory. ; label x1 = "Price" x2 = "Location" x3 = "Financial" x4 = "Health" x5= "Browsinghistory"; rename x1 = Price x2 = Location x3 = Financial x4 = Health x5 = Browsinghistory ; run; proc print label; id set; by set; run; proc print data=desres2; id set; by set; run; %choiceff(data=desres2, /* candidate set of alternatives */ init=desres2(keep=index), /* select these alts from candidates */ intiter=0, /* evaluate without internal iterations */ model=class(price location financial health browsinghistory/ sta), /* model with stdz orthogonal coding */ nsets=10, /* number of choice sets */ flags=4, seed=70, /* 4 alternatives, generic candidates */ options=relative, /* display relative D-efficiency */ beta=zero) /* assumed beta vector, Ho: b=0 */
The error message I'm receiving is:
185 %choiceff(data=desres2, /* candidate set of alternatives */ 186 init=desres2(keep=index), /* select these alts from candidates */ 187 intiter=0, /* evaluate without internal iterations */ 188 model=class(price location financial health browsinghistory/ sta), /* model with stdz orthogonal coding */ 189 nsets=10, /* number of choice sets */ 190 flags=4, 191 seed=70, /* 4 alternatives, generic candidates */ 192 options=relative, /* display relative D-efficiency */ 193 beta=zero) /* assumed beta vector, Ho: b=0 */ ERROR: (execution) Invalid subscript or subscript out of range. operation : [ at line 185 column 1 operands : cand, indvec, cand 40 rows 20 cols (numeric) indvec 1 row 40 cols (numeric) statement : ASSIGN at line 185 column 1 ERROR: The CHOICEFF macro ended abnormally. NOTE: The CHOICEFF macro used 0.09 seconds. 194 195 196 197 198 199 200 201 202 203 204 205 206 207 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK; 217
It seems that the error lies in the line segment 185, but I can't understand exactly what the issue is. I have checked the variables, but they appear to be correct.
Could someone please assist me in identifying the error and understanding why the code is not functioning as expected?
Thank you in advance for your assistance!
That macro is doing a lot. You downloaded it from somewhere like https://support.sas.com/resources/papers/tnote/tnote_marketresearch.html , right? In addition to running it with NOTES and MPRINT turned on, you'll probably want to read through the macro definition itself, to see if you can deduce where something is going wrong. That's an IML error message, so if you know SAS/IML you should be able to trace through the logic and see where there is a conflict in subscripts (e.g. sounds like somewhere the code is asking for the nth column (or row) of a matrix that doesn't have n columns (or rows) ).
It looks like that macro was developed by the great @WarrenKuhfeld , several years retired but might occasionally still be monitoring communities for fun. Maybe you'll get lucky. : )
I'll look at it.
You are first creating a design with the choiceff macro then using the choiceff macro to evaluate it. The first (design creation step) works. Your error was in the evaluation. The problem was you were evaluating a design that has an index variable created in the first step. That index variable refers back to the original candidate set of 68 alternatives. But your design that you use as a candidate set has only 50 observations. So as soon as the macro encounters an index greater than 50, you have an error. The fix is to create a new index, shown before the RUN below, that corresponds to desres2 (your new candidate set) and not to randomized (your first set of candidates).
data desres2;
set desres2;
format x1 price. x2 location. x3 financial. x4 health. x5 browsinghistory. ;
label x1 = "Price" x2 = "Location" x3 = "Financial" x4 = "Health" x5= "Browsinghistory";
rename x1 = Price x2 = Location x3 = Financial x4 = Health x5 = Browsinghistory ;
index = _n_;
run;
As a macro writer, I tried really hard to anticipate and check for every error so it would not result in an IML error, but I missed that one. I retired 4.5 years ago, so it is too late to go back and tweak it. If you have other choiceff or mktex problems, tag me, and I will take a look.
Dear Mr. Kuhlfeld,
thank you very much for your respond! I tried you suggested solution and it works well for my issue.
Thank you for helping me create the study design.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.