/****************************************************************/ /* S A S S A M P L E C O D E */ /* */ /* NAME: TS722F */ /* TITLE: Discrete Choice */ /* PRODUCT: STAT */ /* SYSTEM: ALL */ /* KEYS: marketing research */ /* PROCS: PHREG, TRANSREG, OPTEX, FACTEX, PLAN, IML */ /* DATA: */ /* */ /* SUPPORT: saswfk UPDATE: 01Jan2005 */ /* REF: TS-722F Discrete Choice */ /* MISC: This file contains all of the SAS code for */ /* the "Discrete Choice" report, */ /* the 01Jan2005 edition, for SAS 9.1. This code */ /* should work fine in SAS 8.2 and SAS 9.0 as well. */ /* */ /* You must install the following macros from */ /* http://support.sas.com/techsup/tnote/tnote_stat.html#market */ /* */ /* ChoicEff Efficient Choice Designs */ /* MktAllo Process a Choice Allocation Study Data Set */ /* MktBal Balanced Experimental Design */ /* MktBlock Block an Experimental Design */ /* MktDes Efficient Experimental Designs */ /* MktDups Eliminate Duplicate Runs or Choice Sets */ /* MktEval Evaluate an Experimental Design */ /* MktEx Efficient Experimental Designs */ /* MktKey Aid Making the MktRoll KEY= Data Set */ /* MktLab Change Names, Levels in a Design */ /* MktMerge Merge a Choice Design with Choice Data */ /* MktOrth List Orthogonal Designs MktEx Can Make */ /* MktPPro Optimal Partial Profile Designs */ /* MktRoll Roll Out a Design Into a Choice Design */ /* MktRuns Experimental Design Sizes */ /* PhChoice Customize PROC PHREG for Choice Models */ /* */ /****************************************************************/ options ls=80 ps=60 nonumber nodate; title; ************* Begin PHREG Output Customization **************; %phchoice(on) ***************** Begin Candy Example Code ******************; options ls=80 ps=60 nonumber nodate; title; data x; do u = -2 to 5 by 0.1; p = exp(u) / 234.707; output; end; run; /* proc gplot; title h=1 'Probability of Choice as a Function of Utility'; plot p * u; symbol1 i=join; run; quit; */ title 'Choice of Chocolate Candies'; data chocs; input Subj c Dark Soft Nuts @@; Set = 1; datalines; 1 2 0 0 0 1 2 0 0 1 1 2 0 1 0 1 2 0 1 1 1 1 1 0 0 1 2 1 0 1 1 2 1 1 0 1 2 1 1 1 2 2 0 0 0 2 2 0 0 1 2 2 0 1 0 2 2 0 1 1 2 2 1 0 0 2 1 1 0 1 2 2 1 1 0 2 2 1 1 1 3 2 0 0 0 3 2 0 0 1 3 2 0 1 0 3 2 0 1 1 3 2 1 0 0 3 2 1 0 1 3 1 1 1 0 3 2 1 1 1 4 2 0 0 0 4 2 0 0 1 4 2 0 1 0 4 2 0 1 1 4 1 1 0 0 4 2 1 0 1 4 2 1 1 0 4 2 1 1 1 5 2 0 0 0 5 1 0 0 1 5 2 0 1 0 5 2 0 1 1 5 2 1 0 0 5 2 1 0 1 5 2 1 1 0 5 2 1 1 1 6 2 0 0 0 6 2 0 0 1 6 2 0 1 0 6 2 0 1 1 6 2 1 0 0 6 1 1 0 1 6 2 1 1 0 6 2 1 1 1 7 2 0 0 0 7 1 0 0 1 7 2 0 1 0 7 2 0 1 1 7 2 1 0 0 7 2 1 0 1 7 2 1 1 0 7 2 1 1 1 8 2 0 0 0 8 2 0 0 1 8 2 0 1 0 8 2 0 1 1 8 2 1 0 0 8 1 1 0 1 8 2 1 1 0 8 2 1 1 1 9 2 0 0 0 9 2 0 0 1 9 2 0 1 0 9 2 0 1 1 9 2 1 0 0 9 1 1 0 1 9 2 1 1 0 9 2 1 1 1 10 2 0 0 0 10 2 0 0 1 10 2 0 1 0 10 2 0 1 1 10 2 1 0 0 10 1 1 0 1 10 2 1 1 0 10 2 1 1 1 ; proc print data=chocs noobs; where subj <= 2; var subj set c dark soft nuts; run; title 'Choice of Chocolate Candies'; * Alternative Form of Data Entry; data combos; /* Read the design matrix. */ input Dark Soft Nuts; datalines; 0 0 0 0 0 1 0 1 0 0 1 1 1 0 0 1 0 1 1 1 0 1 1 1 ; data chocs; /* Create the data set. */ input Choice @@; drop choice; /* Read the chosen combo num. */ Subj = _n_; Set = 1; /* Store subj, choice set num. */ do i = 1 to 8; /* Loop over alternatives. */ c = 2 - (i eq choice); /* Designate chosen alt. */ set combos point=i; /* Read design matrix. */ output; /* Output the results. */ end; datalines; 5 6 7 5 2 6 2 6 6 6 ; proc phreg data=chocs outest=betas; strata subj set; model c*c(2) = dark soft nuts / ties=breslow; label dark = 'Dark Chocolate' soft = 'Soft Center' nuts = 'With Nuts'; run; data chocs2; set chocs; Milk = 1 - dark; Chewy = 1 - Soft; NoNuts = 1 - nuts; label dark = 'Dark Chocolate' milk = 'Milk Chocolate' soft = 'Soft Center' chewy = 'Chewy Center' nuts = 'With Nuts' nonuts = 'No Nuts'; run; proc phreg data=chocs2; strata subj set; model c*c(2) = dark milk soft chewy nuts nonuts / ties=breslow; run; * Estimate the probability that each alternative will be chosen; data p; retain sum 0; set combos end=eof; * On the first pass through the DATA step (_n_ is the pass number), get the regression coefficients in B1-B3. Note that they are automatically retained so that they can be used in all passes through the DATA step.; if _n_ = 1 then set betas(rename=(dark=b1 soft=b2 nuts=b3)); keep dark soft nuts p; array x[3] dark soft nuts; array b[3] b1-b3; * For each combination, create x * b; p = 0; do j = 1 to 3; p = p + x[j] * b[j]; end; * Exponentiate x * b and sum them up; p = exp(p); sum = sum + p; * Output sum exp(x * b) in the macro variable '&sum'; if eof then call symput('sum',put(sum,best12.)); run; proc format; value df 1 = 'Dark' 0 = 'Milk'; value sf 1 = 'Soft' 0 = 'Chewy'; value nf 1 = 'Nuts' 0 = 'No Nuts'; run; * Divide each exp(x * b) by sum exp(x * b); data p; set p; p = p / (&sum); format dark df. soft sf. nuts nf.; run; proc sort; by descending p; run; proc print; run; ************* Begin Fabric Softener Example Code ************; options ls=80 ps=60 nonumber nodate; title; title 'Choice of Fabric Softener'; %mktruns( 3 3 3 3 ) %let n = 18; /* n choice sets */ %let m = 5; /* m alternative including constant */ %let mm1 = %eval(&m - 1); /* m - 1 */ proc format; /* create a format for the price */ value price 1 = '$1.49' 2 = '$1.99' 3 = '$2.49' . = '$1.99'; run; %mktex(3 ** 4, n=&n) %mktex(3 ** 4, n=&n, seed=17) * Due to machine differences, you may not get the same design if you run * the step above, so here is the design that was used in the book; data randomized; input x1-x4 @@; datalines; 2 2 2 3 3 1 1 2 1 3 3 1 3 2 3 2 1 1 1 3 1 3 2 2 3 2 2 1 3 3 1 1 2 1 3 1 1 1 2 1 2 3 1 3 1 2 1 2 2 2 1 1 1 2 3 3 3 1 3 3 2 3 3 2 2 1 2 2 3 3 2 3 ; data design; input x1-x4 @@; datalines; 1 1 1 1 1 1 2 2 1 2 1 3 1 2 3 1 1 3 2 3 1 3 3 2 2 1 1 3 2 1 3 1 2 2 2 2 2 2 3 3 2 3 1 2 2 3 2 1 3 1 2 3 3 1 3 2 3 2 1 2 3 2 2 1 3 3 1 1 3 3 3 3 ; proc print; run; %mkteval; %mkteval(data=design, print=freqs) data sasuser.Softener_LinDes; set randomized; format x1-x&mm1 price.; label x1 = 'Sploosh' x2 = 'Plumbbob' x3 = 'Platter' x4 = 'Moosey'; run; proc print data=sasuser.Softener_LinDes label; /* print final design */ title2 'Efficient Design'; run; title2 'Key Data Set'; data key; input Brand $ Price $; datalines; Sploosh x1 Plumbbob x2 Platter x3 Moosey x4 Another . ; proc print; run; %mktroll(design=sasuser.Softener_LinDes, key=key, alt=brand, out=sasuser.Softener_ChDes) title2 'Linear Design (First 3 Sets)'; proc print data=sasuser.Softener_LinDes(obs=3); run; title2 'Choice Design (First 3 Sets)'; proc print data=sasuser.Softener_ChDes(obs=15); format price price.; id set; by set; run; title2 'Evaluate the Choice Design'; %choiceff(data=sasuser.Softener_ChDes, init=sasuser.Softener_ChDes(keep=set), nsets=&n, nalts=&m, beta=zero, intiter=0, model=class(brand price / zero='Another' '$1.99') / lprefix=0 cprefix=0%str(;) format price price.) options ls=80 ps=60 nonumber nodate; title; data _null_; /* print questionnaire */ array brands[&m] $ _temporary_ ('Sploosh' 'Plumbbob' 'Platter' 'Moosey' 'Another'); array x[&m] x1-x&m; file print linesleft=ll; set sasuser.Softener_LinDes; x&m = 2; /* constant alternative */ format x&m price.; if _n_ = 1 or ll < 12 then do; put _page_; put @60 'Subject: _________' //; end; put _n_ 2. ') Circle your choice of ' 'one of the following fabric softeners:' /; do brnds = 1 to &m; put ' ' brnds 1. ') ' brands[brnds] 'brand at ' x[brnds] +(-1) '.' /; end; run; title 'Choice of Fabric Softener'; data results; /* read choice data set */ input Subj (choose1-choose&n) (1.) @@; datalines; 1 334533434233312433 2 334213442433333325 3 333333333333313333 4 334431444434412453 5 335431434233512423 6 334433434433312433 7 334433434433322433 8 334433434433412423 9 334433332353312433 10 325233435233332433 11 334233434433313333 12 334331334433312353 13 534333334333312323 14 134421444433412423 15 334333435433312335 16 334433435333315333 17 534333432453312423 18 334435544433412543 19 334333335433313433 20 331431434233315533 21 334353534433512323 22 334333452233312523 23 334333332333312433 24 525221444233322423 25 354333434433312333 26 334435545233312323 27 334353534233352323 28 334333332333332333 29 334433534335352423 30 334453434533313433 31 354333334333312433 32 354331332233332423 33 334424432353312325 34 334433434433312433 35 334551444453412325 36 334234534433312433 37 334431434433512423 38 354333334433352523 39 334351334333312533 40 324433334433412323 41 334433444433412443 42 334433434433312423 43 334434454433332423 44 334433434233312423 45 334451544433412424 46 434431435433512423 47 524434534433412433 48 335453334433322453 49 334533434133312433 50 334433332333312423 ; proc format; value price 1 = '$1.49' 2 = '$1.99' 3 = '$2.49' . = '$1.99'; run; %mktmerge(design=sasuser.Softener_ChDes, data=results, out=res2, nsets=&n, nalts=&m, setvars=choose1-choose&n) title2 'Choice Design and Data (First 3 Sets)'; proc print data=res2(obs=15); id subj set; by subj set; run; data res3; /* Create a numeric actual price */ set res2; price = input(put(price, price.), dollar5.); label price = 'Price'; run; proc transreg design=5000 data=res3 nozeroconstant norestoremissing; model class(brand / zero=none order=data) identity(price) / lprefix=0; output out=coded(drop=_type_ _name_ intercept); id subj set c; run; proc print data=coded(obs=15) label; title2 'First 15 Observations of Analysis Data Set'; id subj set c; by subj set; run; proc phreg data=coded outest=betas brief; title2 'Discrete Choice Model'; model c*c(2) = &_trgind / ties=breslow; strata subj set; run; proc score data=coded(where=(subj=1) drop=c) score=betas type=parms out=p; var &_trgind; run; data p2; set p; p = exp(c); run; proc means data=p2 noprint; output out=s sum(p) = sp; by set; run; data p; merge p2 s(keep=set sp); by set; p = p / sp; keep brand set price p; run; proc print data=p(obs=15); title2 'Choice Probabilities for the First 3 Choice Sets'; run; %let forms = 50; title2 'Create 50 Custom Questionnaires'; *---Make the design---; %mktex(&forms &n &mm1, n=&forms * &n * &mm1) *---Assign Factor Names---; %mktlab(data=design, vars=Form Set Alt) *---Set up for Random Ordering---; data sasuser.orders; set final; by form set; retain r1; if first.set then r1 = uniform(17); r2 = uniform(17); run; *---Random Sort---; proc sort out=sasuser.orders(drop=r:); by form r1 r2; run; proc print data=sasuser.orders(obs=16); run; proc transpose data=sasuser.orders out=sasuser.orders(drop=_name_); by form notsorted set; run; proc print data=sasuser.orders(obs=18); run; ods listing close; /* suppress a LOT of output */ options ls=80 ps=60 nodate nonumber; title; data _null_; array brands[&mm1] $ _temporary_ ('Sploosh' 'Plumbbob' 'Platter' 'Moosey'); array x[&mm1] x1-x&mm1; array c[&mm1] col1-col&mm1; format x1-x&mm1 price.; file print linesleft=ll; do frms = 1 to &forms; do choice = 1 to &n; if choice = 1 or ll < 12 then do; put _page_; put @60 'Subject: ' frms //; end; put choice 2. ') Circle your choice of ' 'one of the following fabric softeners:' /; set sasuser.orders; set sasuser.Softener_LinDes point=set; do brnds = 1 to &mm1; put ' ' brnds 1. ') ' brands[c[brnds]] 'brand at ' x[c[brnds]] +(-1) '.' /; end; put ' 5) Another brand at $1.99.' /; end; end; stop; run; ods listing; title 'Choice of Fabric Softener'; data results; /* read choice data set */ input Subj (choose1-choose&n) (1.) @@; datalines; 1 524141141211421241 2 532234223321321311 3 223413221434144231 4 424413322222544331 5 123324312534444533 6 233114423441143321 7 123243224422433312 8 312432241121112412 9 315432222144111124 10 511432445343442414 11 331244123342421432 12 323234114312123245 13 312313434224435334 14 143433332142334114 15 234423133531441145 16 425441421454434414 17 234431535341441432 18 235224352241523311 19 134331342432542243 20 335331253334232433 21 513453254214134224 22 212241213544214125 23 133444341431414432 24 453424142151142322 25 324424431252444221 26 244145452131443415 27 553254131423323121 28 233423242432231424 29 322454324541433543 30 323433433135133542 31 412422434342513222 32 243144343352123213 33 441113141133454445 34 131114113312342312 35 325222444355122522 36 342133254432124342 37 511322324114234222 38 522153113442344541 39 211542232314512412 40 244432222212213211 41 241411341323123213 42 314334342111232114 43 422351321313343332 44 124243444234124432 45 141251113314352121 46 414215225442424413 47 333452434454311222 48 334325341342552344 49 335124122444243112 50 244412331342433332 ; proc transpose data=results /* create one obs per choice set */ out=res2(rename=(col1=choose) drop=_name_); by subj; run; data res3(keep=subj set choose); array c[&mm1] col1-col&mm1; merge sasuser.orders res2; if choose < 5 then choose = c[choose]; run; proc sort; by subj set; run; data _null_; set res3; by subj; if first.subj then do; if mod(subj, 3) eq 1 then put; put subj 4. +1 @@; end; put choose 1. @@; run; **************** Begin Vacation Example Code ****************; options ls=80 ps=60 nonumber nodate; title; title 'Vacation Example'; %mktruns( 3 ** 15 ) %mktorth(range=n=36) proc sort data=mktdeslev out=list(drop=x:); by descending x3; where x3; run; proc print; run; %let m = 6; /* m alts including constant */ %let mm1 = %eval(&m - 1); /* m - 1 */ %let n = 18; /* number of choice sets per person */ %let blocks = 2; /* number of blocks */ %mktex(3 ** 15 2, n=&n * &blocks, seed=151) * Due to machine differences, you may not get the same design if you run * the step above, so here is the design that was used in the book; data randomized; input x1-x16 @@; datalines; 1 1 3 3 1 3 3 1 2 1 2 1 3 3 3 2 3 1 3 2 2 3 3 2 1 2 1 2 2 2 2 2 3 3 1 2 1 2 1 1 1 1 2 2 3 1 1 2 1 3 3 1 1 1 1 2 2 2 3 2 1 3 1 1 3 2 3 1 1 1 3 3 1 3 2 3 1 2 2 2 1 2 1 2 3 1 3 1 1 2 3 1 2 2 3 1 2 3 3 3 2 3 1 3 3 3 2 2 2 2 3 1 3 3 2 3 1 3 2 3 1 2 3 1 3 2 1 1 3 2 1 3 3 3 1 2 2 2 2 3 1 1 3 1 3 1 3 2 3 2 1 3 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ks, init=randomized(drop=x16), options=check, examine=i v) %mktlab(data=randomized, vars=x1-x5 x11-x15 x6 x9 x7 x8 x10 Block, out=sasuser.Vacation_LinDesBlckd) proc sort data=sasuser.Vacation_LinDesBlckd; by block; run; %mkteval(blocks=block) %mktkey(5 3 t) title 'Vacation Example'; data key; input Place $ 1-10 (Lodge Scene Price) ($); datalines; Hawaii x1 x6 x11 Alaska x2 x7 x12 Mexico x3 x8 x13 California x4 x9 x14 Maine x5 x10 x15 Home . . . ; %mktroll(design=sasuser.Vacation_LinDesBlckd, key=key, alt=place, out=sasuser.Vacation_ChDes) proc print data=sasuser.Vacation_LinDesBlckd(obs=2); id Block; var x1-x15; run; proc print data=sasuser.Vacation_ChDes(obs=12); id set; by set; run; proc format; value price 1 = ' 999' 2 = '1249' 3 = '1499' 0 = ' 0'; value scene 1 = 'Mountains' 2 = 'Lake' 3 = 'Beach' 0 = 'Home'; value lodge 1 = 'Cabin' 2 = 'Bed & Breakfast' 3 = 'Hotel' 0 = 'Home'; run; data sasuser.Vacation_ChDes; set sasuser.Vacation_ChDes; if place = 'Home' then do; lodge = 0; scene = 0; price = 0; end; price = input(put(price, price.), 5.); format scene scene. lodge lodge.; run; proc print data=sasuser.Vacation_ChDes(obs=12); id set; by set; run; title2 'Evaluate the Choice Design'; %choiceff(data=sasuser.Vacation_ChDes, init=sasuser.Vacation_ChDes(keep=set), nsets=36, nalts=6, beta=zero, intiter=0, model=class(place / zero=none order=data) class(place * price place * scene place * lodge / zero='Home' '0' 'Home' 'Home' order=formatted) / lprefix=0 cprefix=0 separators=' ' ', ') ods listing close; /* suppress a LOT of output */ title; proc sort data=sasuser.Vacation_LinDesBlckd; by block; run; options ls=80 ps=60 nodate nonumber; data _null_; array dests[&mm1] $ 10 _temporary_ ('Hawaii' 'Alaska' 'Mexico' 'California' 'Maine'); array prices[3] $ 5 _temporary_ ('$999' '$1249' '$1499'); array scenes[3] $ 13 _temporary_ ('the Mountains' 'a Lake' 'the Beach'); array lodging[3] $ 15 _temporary_ ('Cabin' 'Bed & Breakfast' 'Hotel'); array x[15]; file print linesleft=ll; set sasuser.Vacation_LinDesBlckd; by block; if first.block then do; choice = 0; put _page_; put @50 'Form: ' block ' Subject: ________' //; end; choice + 1; if ll < 19 then put _page_; put choice 2. ') Circle your choice of ' 'vacation destinations:' /; do dest = 1 to &mm1; put ' ' dest 1. ') ' dests[dest] +(-1) ', staying in a ' lodging[x[dest]] 'near ' scenes[x[&mm1 + dest]] +(-1) ',' / ' with a package cost of ' prices[x[2 * &mm1 + dest]] +(-1) '.' /; end; put " &m) Stay at home this year." /; run; ods listing; title 'Vacation Example'; data results; input Subj Form (choose1-choose&n) (1.) @@; datalines; 1 1 111353313351554151 2 2 344113155513111413 3 1 132353331151534151 4 2 341133131523331143 5 1 142153111151334143 6 2 344114111543131151 7 1 141343111311154154 8 2 344113111343121111 9 1 141124131151342155 10 2 344113131523131141 11 1 311423131353524144 12 2 332123151413331151 13 1 311244331352134155 14 2 341114111543131153 15 1 141253111351344151 16 2 344135131323331143 17 1 142123313154132141 18 2 542113151323131141 19 1 145314111311144111 20 2 344111131313431143 21 1 133343131313432145 22 2 344141151213131153 23 1 113453411153334155 24 2 343145151511131153 25 1 141434111152332144 26 2 334415131511121141 27 1 344144113151334144 28 2 544344131531131115 29 1 313424133351334151 30 2 344114135513124141 31 1 131413321111334154 32 2 354113151541131141 33 1 114423121315534144 34 2 344431151541115141 35 1 141324311331334151 36 2 344114155343131141 37 1 112423333353534151 38 2 352134131323331141 39 1 112424615353334151 40 2 444115151523131141 41 1 131123111312532154 42 2 344111131513131131 43 1 312443131355341155 44 2 344111131333431141 45 1 311453111311534124 46 2 332111131523134151 47 1 112153333351534111 48 2 342113151513331141 49 1 114453311351334151 50 2 343115131323132141 51 1 112324333311542144 52 2 341411151313121154 53 1 143453113353334151 54 2 344113151513134141 55 1 311314111113334144 56 2 344111151343331151 57 1 111423333153134151 58 2 544114131523331131 59 1 314144311313134141 60 2 344124131253131143 61 1 112224121351132141 62 2 344311431523331143 63 1 132223233313332151 64 2 344124151323331155 65 1 141444313351154154 66 2 341131151333131151 67 1 112443111311354141 68 2 342144151523135145 69 1 312453133353134114 70 2 343114431343334141 71 1 353443333311534151 72 2 351114151323335154 73 1 134124133311334141 74 2 341111151513131143 75 1 142123131111334151 76 2 331144131543131141 77 1 145353313131532154 78 2 355134131523121151 79 1 115443311355334121 80 2 344111131323131111 81 1 151223113152332123 82 2 344114135323134141 83 1 111114311142132125 84 2 554113135323111131 85 1 311423135351332144 86 2 344141151513131145 87 1 113154111353334151 88 2 342114151523331111 89 1 115414111151332154 90 2 345115451521134111 91 1 141153131131131154 92 2 344114111513141143 93 1 314443531152134153 94 2 344111131323121151 95 1 115123111352534151 96 2 541143151223111151 97 1 142324113342532153 98 2 344114151533331143 99 1 112424113351334154 100 2 344114131333134141 101 1 111414113355114544 102 2 544113451321334511 103 1 111424311353334134 104 2 341115155313324141 105 1 131314331353132151 106 2 344143131523331141 107 1 233444311353332154 108 2 344113131513234141 109 1 141144121353534154 110 2 343131151251331151 111 1 341443313131334151 112 2 341114151523131134 113 1 131424311121532144 114 2 341114151333341143 115 1 111143123311144544 116 2 343114431541111343 117 1 111123113313134154 118 2 344114151523331141 119 1 111123333111533154 120 2 344113131523131151 121 1 212244111154334151 122 2 342114151343334141 123 1 141123513354544144 124 2 354131431343131151 125 1 132313313351334121 126 2 334115151331135153 127 1 312423131453144154 128 2 344415131513531143 129 1 112423331353534151 130 2 341111151333136153 131 1 141453113131132151 132 2 344115131343231153 133 1 115444131351444553 134 2 344114451513321154 135 1 112653131351334145 136 2 544115151253131141 137 1 112113131321334141 138 2 344114131213334141 139 1 313444511353334121 140 2 344113131323131111 141 1 142123111353134151 142 2 342113151333135141 143 1 111413133352143144 144 2 334131151513131131 145 1 135443311353134144 146 2 345114451521121141 147 1 112424313352331141 148 2 344113151313321144 149 1 112313111351144151 150 2 344115231523131151 151 1 115424611351534154 152 2 344113151453334143 153 1 241143111351534154 154 2 344114131211331151 155 1 114434331311134141 156 2 344114131524331113 157 1 112314311154432145 158 2 341113151353111131 159 1 131454131353332141 160 2 341114151223131351 161 1 111124111315332141 162 2 344143155551131141 163 1 113413311352135554 164 2 342113155523331143 165 1 111443111151334154 166 2 344111131323134143 167 1 112124111313154354 168 2 344113131333131151 169 1 115424513353134151 170 2 544114131343421141 171 1 112444331363334141 172 2 342114131323331151 173 1 112444111351534154 174 2 354141151523331111 175 1 213414311353334141 176 2 344143151533331143 177 1 114434133311314151 178 2 344114151523331113 179 1 141113311354534151 180 2 341144131334321141 181 1 241453113113534154 182 2 344113135223131151 183 1 111444113351514145 184 2 351414151323111113 185 1 142423131351332154 186 2 344134151513131145 187 1 313123131352134121 188 2 341143151323131144 189 1 115443133151534151 190 2 333134151123331141 191 1 112423111351134154 192 2 344411151253321153 193 1 111113311351131141 194 2 334115131523331133 195 1 112123113313534151 196 2 345124155313331144 197 1 142154311311434151 198 2 344115151323121141 199 1 141423111351534154 200 2 342131451313134141 ; %mktmerge(design=sasuser.Vacation_ChDes, data=results, out=res2, blocks=form, nsets=&n, nalts=&m, setvars=choose1-choose&n) proc print data=res2(obs=12); id subj form set; by subj form set; run; proc transreg design=5000 data=res2 nozeroconstant norestoremissing; model class(place / zero=none order=data) class(price scene lodge / zero=none order=formatted) / lprefix=0; output out=coded(drop=_type_ _name_ intercept); id subj set form c; run; proc print data=coded(obs=6); id place; var subj set form c price scene lodge; run; proc print data=coded(obs=6) label; var pl:; run; proc print data=coded(obs=6) label; id place; var sc:; run; proc print data=coded(obs=6) label; id place; var lo: pr:; run; proc phreg data=coded brief; model c*c(2) = &_trgind / ties=breslow; strata subj set; run; %put &_trgind; proc transreg design data=res2 nozeroconstant norestoremissing; model class(place / zero='Home' order=data) identity(price) class(scene lodge / zero='Home' 'Home' order=formatted) / lprefix=0; output out=coded(drop=_type_ _name_ intercept); label price = 'Price'; id subj set form c; run; proc phreg data=coded brief; model c*c(2) = &_trgind / ties=breslow; strata subj set; run; data res3; set res2; PriceL = price; if price then pricel = (price - 1249) / 250; run; proc transreg design=5000 data=res3 nozeroconstant norestoremissing; model class(place / zero='Home' order=data) pspline(pricel / degree=2) class(scene lodge / zero='Home' 'Home' order=formatted) / lprefix=0; output out=coded(drop=_type_ _name_ intercept); label pricel = 'Price'; id subj set form c; run; proc phreg data=coded brief; model c*c(2) = &_trgind / ties=breslow; strata subj set; run; data res4; set res3; if scene = 0 then scene = .; if lodge = 0 then lodge = .; run; proc transreg design=5000 data=res4 nozeroconstant norestoremissing; model class(place / zero='Home' order=data) pspline(pricel / degree=2) class(scene lodge / effects zero='Mountains' 'Hotel' order=formatted) / lprefix=0; output out=coded(drop=_type_ _name_ intercept); label pricel = 'Price'; id subj set form c; run; proc print data=coded(obs=6) label; run; proc phreg data=coded brief; model c*c(2) = &_trgind / ties=breslow; strata subj set; run; data key; input Place $ 1-10 (Lodge Scene Price) ($); datalines; Hawaii x1 x6 x11 Alaska x2 x7 x12 Mexico x3 x8 x13 California x4 x9 x14 Maine x5 x10 x15 . . . . ; %mktroll(design=sasuser.Vacation_LinDesBlckd, key=key, alt=place, out=sasuser.Vacation_ChDes) %mktmerge(design=sasuser.Vacation_ChDes, data=results, out=res2, blocks=form, nsets=&n, nalts=&m, setvars=choose1-choose&n, stmts=%str(price = input(put(price, price.), 5.); format scene scene. lodge lodge.;)) proc print data=res2(obs=12); run; proc transreg design=5000 data=res2 nozeroconstant norestoremissing; model class(place / zero=none order=data) class(place * price place * scene place * lodge / zero=none order=formatted) / lprefix=0 sep=' ' ', '; output out=coded(drop=_type_ _name_ intercept); id subj set form c; run; proc print data=coded(obs=6) label noobs; run; proc phreg data=coded brief; model c*c(2) = &_trgind / ties=breslow; strata subj set; run; *********** Begin Asymmetric Vacation Example Code **********; options ls=80 ps=60 nonumber nodate; title; title 'Vacation Example with Asymmetry'; %mktruns( 3 ** 14 4 2 2 ) %mktex(3 ** 13 4 3 2 2, n=36, seed=205) %mkteval; title 'Vacation Example with Asymmetry'; %mktruns(3 ** 13 4 3 2 2, interact=x1*x11 x2*x12 x3*x13 x4*x14 x5*x15, max=45) %mktex(3 ** 13 4 3 2 2, n=72, seed=368, interact=x1*x11 x2*x12 x3*x13 x4*x14 x5*x15) data mat; do a = 1 to 17; b = .; output; end; do a = 1 to 5; b = 10 + a; output; end; run; proc print; run; %mktex(3 ** 13 4 3 2 2, n=72, seed=368, order=matrix=mat, interact=x1*x11 x2*x12 x3*x13 x4*x14 x5*x15) * Due to machine differences, you may not get the same design if you run * the step above, so here is the design that was used in the book; data randomized; input x1-x17 @@; datalines; 2 2 1 1 3 2 1 2 2 3 2 1 1 2 2 2 2 3 2 3 1 2 1 3 3 1 1 1 1 1 3 2 2 2 1 1 3 2 1 1 1 1 3 3 3 3 1 4 1 1 2 2 3 1 1 3 1 3 2 3 1 3 3 3 1 2 2 2 3 3 3 1 1 2 2 3 3 2 3 2 2 1 2 1 2 3 3 2 3 3 1 1 2 1 2 2 1 3 3 2 1 1 3 3 2 1 2 1 1 3 2 1 3 3 2 2 1 1 1 1 1 1 2 1 2 3 1 3 2 2 2 2 2 1 1 1 2 2 1 2 1 1 1 1 2 3 1 2 2 1 2 2 2 1 3 2 2 2 1 3 2 2 1 3 2 3 2 3 1 2 1 1 3 1 2 1 1 2 1 3 1 1 3 1 1 2 2 1 2 3 3 3 1 2 1 1 2 3 1 3 1 1 1 1 3 1 1 1 3 3 2 2 1 2 1 3 2 2 3 2 2 3 1 2 3 1 1 2 2 2 2 1 2 1 2 3 1 1 3 2 2 2 1 3 1 2 3 1 2 1 2 1 1 1 2 1 3 1 3 1 3 1 1 3 3 1 2 3 3 3 2 2 2 3 1 3 2 2 3 2 3 2 2 1 2 4 1 1 2 3 1 3 2 1 2 2 1 1 1 2 1 2 2 3 2 2 2 3 1 1 1 1 2 2 1 2 3 2 1 4 1 1 1 2 2 2 3 2 2 2 1 2 2 3 1 1 3 1 1 2 3 3 3 2 2 3 3 1 3 3 1 2 2 3 1 1 1 2 2 3 2 3 2 3 2 3 3 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1 2 3 1 3 4 3 1 1 3 3 3 1 2 2 1 3 2 1 3 2 1 2 2 2 2 3 3 3 3 3 1 1 3 2 2 2 3 2 4 3 1 2 ; %mkteval(data=design); %mktex(3 ** 13 4 3 2 2, n=72, examine=i v, options=check, init=randomized, interact=x1*x11 x2*x12 x3*x13 x4*x14 x5*x15) %mktblock(data=randomized, nblocks=4, out=sasuser.AsymVac_LinDesBlckd, seed=114) proc format; value price 1 = ' 999' 2 = '1249' 3 = '1499' 4 = '1749' . = ' '; value scene 1 = 'Mountains' 2 = 'Lake' 3 = 'Beach' . = ' '; value lodge 1 = 'Cabin' 2 = 'Bed & Breakfast' 3 = 'Hotel' . = ' '; value side 1 = 'Side Trip' 2 = 'No' . = ' '; run; data key; input Place $ 1-10 (Lodge Scene Price Side) ($); datalines; Hawaii x1 x6 x11 x16 Alaska x2 x7 x12 . Mexico x3 x8 x13 x17 California x4 x9 x14 . Maine x5 x10 x15 . . . . . . ; data temp; set sasuser.AsymVac_LinDesBlckd(rename=(block=Form)); x11 + 1; x12 + 1; run; %mktroll(design=temp, key=key, alt=place, out=sasuser.AsymVac_ChDes, options=nowarn, keep=form) data sasuser.AsymVac_ChDes; set sasuser.AsymVac_ChDes; format scene scene. lodge lodge. side side. price price.; run; proc print data=sasuser.AsymVac_ChDes(obs=12); by form set; id form set; run; title2 'Evaluate the Choice Design'; %choiceff(data=sasuser.AsymVac_ChDes, init=sasuser.AsymVac_ChDes(keep=set), nsets=72, nalts=6, beta=zero, intiter=0, model=class(place / zero=none order=data) class(place * price place * scene place * lodge / zero=none order=formatted separators='' ' ') class(place * side / zero=' ' 'No' separators='' ' ') / lprefix=0 cprefix=0) ods listing close; /* suppress a LOT of output */ %let m = 6; /* m alts including constant */ %let mm1 = %eval(&m - 1); /* m - 1 */ %let n = 18; /* number of choice sets */ %let blocks = 4; /* number of blocks */ title; options ls=80 ps=60 nonumber nodate; data _null_; array dests[&mm1] $ 10 _temporary_ ('Hawaii' 'Alaska' 'Mexico' 'California' 'Maine'); array scenes[3] $ 13 _temporary_ ('the Mountains' 'a Lake' 'the Beach'); array lodging[3] $ 15 _temporary_ ('Cabin' 'Bed & Breakfast' 'Hotel'); array x[15]; array p[&mm1]; length price $ 6; file print linesleft=ll; set sasuser.AsymVac_LinDesBlckd; by block; p1 = 1499 + (x[11] - 2) * 250; p2 = 1499 + (x[12] - 2) * 250; p3 = 1249 + (x[13] - 2) * 250; p4 = 1374 + (x[14] - 2.5) * 250; p5 = 1249 + (x[15] - 2) * 250; if first.block then do; choice = 0; put _page_; put @50 'Form: ' block ' Subject: ________' //; end; choice + 1; if ll < (19 + (x16 = 1) + (x17 = 1)) then put _page_; put choice 2. ') Circle your choice of ' 'vacation destinations:' /; do dest = 1 to &mm1; price = left(put(p[dest], dollar6.)); put ' ' dest 1. ') ' dests[dest] +(-1) ', staying in a ' lodging[x[dest]] 'near ' scenes[x[&mm1 + dest]] +(-1) ',' / +7 'with a package cost of ' price +(-1) @@; if dest = 3 and x16 = 1 then put ', and an optional visit' / +7 'to archaeological sites for an additional $100' @@; else if dest = 1 and x17 = 1 then put ', and an optional helicopter' / +7 'flight to an active volcano for an additional $200' @@; put '.' /; end; put " &m) Stay at home this year." /; run; ods listing; data _null_; array dests[&mm1] _temporary_ (5 -1 4 3 2); array scenes[3] _temporary_ (-1 0 1); array lodging[3] _temporary_ (0 3 2); array u[&m]; array x[15]; do rep = 1 to 100; n = 0; do i = 1 to &blocks; k + 1; if mod(k,3) = 1 then put; put k 3. +1 i 1. +2 @@; do j = 1 to &n; n + 1; set sasuser.AsymVac_LinDesBlckd point=n; do dest = 1 to &mm1; u[dest] = dests[dest] + lodging[x[dest]] + scenes[x[&mm1 + dest]] - x[2 * &mm1 + dest] + 2 * normal(17); end; u[1] = u[1] + (x16 = 1); u[3] = u[3] + (x17 = 1); u&m = -3 + 3 * normal(17); m = max(of u1-u&m); if abs(u1 - m) < 1e-4 then c = 1; else if abs(u2 - m) < 1e-4 then c = 2; else if abs(u3 - m) < 1e-4 then c = 3; else if abs(u4 - m) < 1e-4 then c = 4; else if abs(u5 - m) < 1e-4 then c = 5; else c = 6; put +(-1) c @@; end; end; end; stop; run; options ls=80 ps=60 nonumber nodate; title 'Vacation Example with Asymmetry'; %let m = 6; %let mm1 = %eval(&m - 1); %let n = 18; %let blocks = 4; data results; input Subj Form (choose1-choose&n) (1.) @@; datalines; 1 1 413414111315351335 2 2 115311141441134121 3 3 331451344433513341 4 4 113111143133311314 5 1 113413531545431313 6 2 145131111414331511 7 3 313413113111313331 8 4 415143311133541321 9 1 133314111133431113 10 2 543311131111333413 11 3 241353113111313311 12 4 113111311133343311 13 1 113411111131353334 14 2 441111531411131411 15 3 333311144111413311 16 4 413111141133313311 17 1 133114111535451313 18 2 313311131311131313 19 3 333115114111414311 20 4 113411313133333511 21 1 133411111133453335 22 2 113335113443331331 23 3 153411113111413331 24 4 114111111333313311 25 1 133511432133133335 26 2 541145131311134111 27 3 313311133131413331 28 4 431111341331313351 29 1 143111151133431311 30 2 145341131311131411 31 3 331353113111414311 32 4 414111143153343311 33 1 113111531113131313 34 2 145111111413331313 35 3 311311113111113311 36 4 413111141334343633 37 1 333414111112413354 38 2 441311133111131111 39 3 313313313111534331 40 4 413111111333343331 41 1 511514111131455313 42 2 115341134441111441 43 3 333411113111411331 44 4 133411413314113311 45 1 133311431113343344 46 2 145141413341331113 47 3 133311111111413331 48 4 113411113331343311 49 1 133311111133411113 50 2 115135143413333311 51 3 134351313111514331 52 4 114111543433313351 53 1 114514431113151333 54 2 145133133451331113 55 3 333311313111433311 56 4 534411115133513351 57 1 133311411111431333 58 2 141311111141131511 59 3 333111111111413313 60 4 412411111433333313 61 1 114511111343331133 62 2 545335113111131413 63 3 231311113111514335 64 4 113131141433115133 65 1 113514111113431113 66 2 143313133441331311 67 3 351413113135534313 68 4 114111113431533351 69 1 113313113111431331 70 2 115315533311344311 71 3 353411313511513335 72 4 114411111133311311 73 1 513514112533331333 74 2 413111133411133113 75 3 331411311111513311 76 4 114411113333333311 77 1 133414111113531153 78 2 115113133445111323 79 3 341413114111513331 80 4 413411111333313311 81 1 111311131513331313 82 2 113313111311133411 83 3 341313113511413331 84 4 413111313133313311 85 1 111414415143451136 86 2 415136331446131413 87 3 335511113151513311 88 4 414111341431343151 89 1 131311131115451133 90 2 111311531411133311 91 3 531113111111313311 92 4 413411113133313111 93 1 131311131133131331 94 2 441111133441131311 95 3 333313111111313333 96 4 514111311133334331 97 1 113311411113531311 98 2 143113131541131111 99 3 333413113131414331 100 4 114113313133331311 101 1 113511164113111433 102 2 141311113341333313 103 3 351413133115511311 104 4 115411341133113321 105 1 113414131115151135 106 2 115313131441131111 107 3 333313311111533311 108 4 413111151531313311 109 1 113414131113153333 110 2 415331111441131441 111 3 353411113111414311 112 4 113111143133313311 113 1 113111431115553313 114 2 545313511314333311 115 3 131313113151333331 116 4 114111141134313334 117 1 133311411113311315 118 2 113311111441133313 119 3 341314134411511315 120 4 113111111133333331 121 1 133431111113533335 122 2 443315141254131113 123 3 331311113113413331 124 4 414411113313311151 125 1 313411113113131133 126 2 145111133311331113 127 3 131414113111513311 128 4 414111351433343355 129 1 131311131115352333 130 2 415331131311131113 131 3 111114111111414351 132 4 114111511313343331 133 1 113514111313431333 134 2 143131131341331413 135 3 331313113111414311 136 4 114411141433313311 137 1 313411114113411333 138 2 113333113354331341 139 3 153411114153313335 140 4 114111311531513333 141 1 545511133113411141 142 2 165113113345131311 143 3 253411211111431351 144 4 113111111333313334 145 1 113211111543131154 146 2 445311111343134513 147 3 111314111131114331 148 4 113453415313131331 149 1 243314431335151113 150 2 415343113651111313 151 3 143314113111313111 152 4 115113513333313321 153 1 555311111511351331 154 2 445311111111134323 155 3 144453113111513331 156 4 112111111334531351 157 1 111414431335444115 158 2 415111131141131333 159 3 351511111111513311 160 4 113111311134313333 161 1 115411111131511313 162 2 455313111144131411 163 3 211413111111414315 164 4 113111111153343311 165 1 143211133113411133 166 2 111315331323331113 167 3 133341111131313331 168 4 114411151133341313 169 1 143511132115431313 170 2 145111111341331123 171 3 331311113131411315 172 4 414111151114313334 173 1 313514111513551113 174 2 141141131541344513 175 3 141313313113413315 176 4 434113111433143343 177 1 113414111543334333 178 2 345311111441111321 179 3 131411113111413311 180 4 115111313133533334 181 1 153413111545351335 182 2 145341111351131111 183 3 313133313411413341 184 4 413111111533343331 185 1 131411111111131133 186 2 445313111311351423 187 3 141311143111513331 188 4 414111111133333333 189 1 131311111333153151 190 2 115335111441334411 191 3 333311111151413413 192 4 413111111543131311 193 1 533113111513551331 194 2 345135113444333511 195 3 343314114111413311 196 4 433111151133363331 197 1 133515131113353113 198 2 141314131341131141 199 3 151311111151313331 200 4 115513311131133111 201 1 133413413336133133 202 2 415111131311334411 203 3 131311111111414311 204 4 114141113333313331 205 1 133411411531411311 206 2 115333111464331113 207 3 153413214451314315 208 4 133411331113313533 209 1 113511111313431331 210 2 111113111111333313 211 3 131311113511413311 212 4 433111151433533311 213 1 113511111343332111 214 2 145311113121331111 215 3 331151113411413331 216 4 413111113131133311 217 1 113311111133351313 218 2 113111331441331313 219 3 331311143111633351 220 4 413111413334233311 221 1 113413111513541351 222 2 245143111441331111 223 3 331111334111531331 224 4 115111313331341344 225 1 113413313315443315 226 2 115113131341133313 227 3 115414111111514311 228 4 413141111133333333 229 1 133513114135141331 230 2 543311133411131411 231 3 141413111411311311 232 4 113141133133343311 233 1 133511111135133131 234 2 131113333411331313 235 3 143311113131531331 236 4 415111151113313311 237 1 131511131113153133 238 2 145111131541131313 239 3 331413113115413311 240 4 111411331333143315 241 1 133414133313143313 242 2 113341111411331313 243 3 334314114131113331 244 4 114411151314343111 245 1 133411113133151314 246 2 141431513451331311 247 3 331453133115413331 248 4 113111113133311111 249 1 133311113113411343 250 2 415343113441133313 251 3 331311113111433311 252 4 413111113333131321 253 1 513113111513553134 254 2 313111131441631111 255 3 151313114411315311 256 4 414111111134543311 257 1 113311133133351313 258 2 145331111341331413 259 3 141311113111433361 260 4 114111343133413311 261 1 331411131535311333 262 2 115111131351131311 263 3 133311114115533331 264 4 114111111333313311 265 1 133514162113151334 266 2 515111511343134411 267 3 131553114111413331 268 4 413111111333311351 269 1 133331131113151335 270 2 345114111151334311 271 3 333411114115514331 272 4 514414431431313331 273 1 133413433113151313 274 2 415135513341331113 275 3 333353144111411311 276 4 113111511134341314 277 1 433513131111331311 278 2 345311113111331111 279 3 343113113113314331 280 4 134113141133313311 281 1 313311311313453311 282 2 145341131345333143 283 3 331411113411313335 284 4 514411533313343331 285 1 113414134133531133 286 2 115131531114131113 287 3 141413111111414311 288 4 113411541134533311 289 1 133311431535313331 290 2 115311131311133511 291 3 153454111111511335 292 4 454411113334333311 293 1 133111431143553333 294 2 441311131441131111 295 3 332413113111513331 296 4 111411113133141321 297 1 145333211133554133 298 2 115311511444111311 299 3 161454111131514313 300 4 113111411154333311 301 1 113314111132351133 302 2 143311131241331113 303 3 355311113111411311 304 4 413111141133333331 305 1 313211433513541333 306 2 134313111421333111 307 3 345511113111413311 308 4 414113341133533313 309 1 433411111513331351 310 2 145411316311131311 311 3 351534111151413331 312 4 413111111533331311 313 1 111411111113451313 314 2 413311133413133313 315 3 313451113113514311 316 4 413113611113363313 317 1 133111511111313113 318 2 343413513424331311 319 3 131311143111313311 320 4 411411113353511341 321 1 133554131133431113 322 2 141111111411133133 323 3 135354114113413311 324 4 114111311333331311 325 1 133414114113151133 326 2 145341131341333113 327 3 231111113111111311 328 4 113411113131441331 329 1 115314111135431133 330 2 445411311441133313 331 3 153351114111315335 332 4 415111143333343311 333 1 533311434343151334 334 2 141313131441131313 335 3 331414113115533311 336 4 134411113331341311 337 1 333414431315331113 338 2 431331131311331411 339 3 133411113151513331 340 4 414111353334333111 341 1 113514111115411311 342 2 145311113413131313 343 3 133311111114513331 344 4 114411341131513321 345 1 513213111115451331 346 2 115311131351133411 347 3 333411113435413351 348 4 114111353134311331 349 1 133411111113131333 350 2 445115111311334311 351 3 331413111111433311 352 4 412111153333114311 353 1 113311111531431333 354 2 113315131311331313 355 3 333411144131413331 356 4 414111353134331151 357 1 533411111131343333 358 2 115363131311331311 359 3 333213113131314311 360 4 414141153133113311 361 1 533514111313411113 362 2 443311111351331311 363 3 141411114131431311 364 4 111111151434315351 365 1 443314131115441333 366 2 545141111441133313 367 3 131311113131511311 368 4 111111153333343321 369 1 311311114145333311 370 2 541313111343333413 371 3 141413134131311331 372 4 413411443333513311 373 1 133411113513153133 374 2 543321331411131513 375 3 333413313111514331 376 4 114411153114311311 377 1 113514111113441113 378 2 113313111441334111 379 3 311413144151411311 380 4 114111141134113321 381 1 133114111115411113 382 2 545311511411131411 383 3 253411114311313311 384 4 114411113633333311 385 1 123411411533151115 386 2 145131111411334111 387 3 131113113111413311 388 4 411111111333344311 389 1 113514111313431134 390 2 645111113314331121 391 3 133313133531514311 392 4 113141313134311311 393 1 111511111315131343 394 2 411113111151113321 395 3 133111111511514311 396 4 114111111331313341 397 1 331311431513163313 398 2 115133111313133111 399 3 313311114111413311 400 4 115511141534111131 ; %mktmerge(design=sasuser.AsymVac_ChDes, data=results, out=res2, blocks=form, nsets=&n, nalts=&m, setvars=choose1-choose&n, stmts=%str(price = input(put(price, price.), 5.); format scene scene. lodge lodge. side side.;)) proc print data=res2(obs=18); id form subj set; by form subj set; run; proc transreg design=5000 data=res2 nozeroconstant norestoremissing; model class(place / zero=none order=data) class(price scene lodge / zero=none order=formatted) class(place * side / zero=' ' 'No' separators='' ' ') / lprefix=0; output out=coded(drop=_type_ _name_ intercept); id subj set form c; run; proc print data=coded(obs=6) label; run; proc phreg data=coded brief; model c*c(2) = &_trgind / ties=breslow; strata subj set; run; proc summary data=coded nway; class form set c &_trgind; output out=agg(drop=_type_); run; proc phreg data=agg; model c*c(2) = &_trgind / ties=breslow; freq _freq_; strata form set; run; ************** Begin Brand Choice Example Code **************; options ls=80 ps=60 nonumber nodate; title; %let m = 5; /* Number of Brands in Each Choice Set */ /* (including Other) */ title 'Brand Choice Example, Multinomial Logit Model'; proc format; value brand 1 = 'Brand 1' 2 = 'Brand 2' 3 = 'Brand 3' 4 = 'Brand 4' 5 = 'Other'; run; data price; array p[&m] p1-p&m; /* Prices for the Brands */ array f[&m] f1-f&m; /* Frequency of Choice */ input p1-p&m f1-f&m; keep subj set brand price c p1-p&m; * Store choice set and subject number to stratify; Set = _n_; Subj = 0; do i = 1 to &m; /* Loop over the &m frequencies */ do ci = 1 to f[i]; /* Loop frequency of choice times */ subj + 1; /* Subject within choice set */ do Brand = 1 to &m; /* Alternatives within choice set */ Price = p[brand]; * Output first choice: c=1, unchosen: c=2; c = 2 - (i eq brand); output; end; end; end; format brand brand.; datalines; 3.99 5.99 3.99 5.99 4.99 4 29 16 42 9 5.99 5.99 5.99 5.99 4.99 12 19 22 33 14 5.99 5.99 3.99 3.99 4.99 34 26 8 27 5 5.99 3.99 5.99 3.99 4.99 13 37 15 27 8 5.99 3.99 3.99 5.99 4.99 49 1 9 37 4 3.99 5.99 5.99 3.99 4.99 31 12 6 18 33 3.99 3.99 5.99 5.99 4.99 37 10 5 35 13 3.99 3.99 3.99 3.99 4.99 16 14 5 51 14 ; proc print data=price(obs=15); var subj set c price brand; run; proc print data=price(obs=5); run; proc transreg design data=price nozeroconstant norestoremissing; model class(brand / zero=none) identity(price) / lprefix=0; output out=coded(drop=_type_ _name_ intercept); label price = 'Price'; id subj set c; run; proc phreg data=coded brief; title2 'Discrete Choice with Common Price Effect'; model c*c(2) = &_trgind / ties=breslow; strata subj set; run; proc transreg design data=price nozeroconstant norestoremissing; model class(brand / zero=none separators='' ' ') | identity(price) / lprefix=0; output out=coded(drop=_type_ _name_ intercept); label price = 'Price'; id subj set c; run; proc print data=coded(obs=10) label; title2 'Discrete Choice with Brand by Price Effects'; var subj set c brand price &_trgind; run; proc phreg data=coded brief; model c*c(2) = &_trgind / ties=breslow; strata subj set; run; title2; proc print data=price(obs=5) label; run; proc transreg design data=price nozeroconstant norestoremissing; model class(brand / zero=none separators='' ' ') | identity(price) identity(p1-p&m) * class(brand / zero=none lprefix=0 separators='' ' on ') / lprefix=0; output out=coded(drop=_type_ _name_ intercept); label price = 'Price' p1 = 'Brand 1' p2 = 'Brand 2' p3 = 'Brand 3' p4 = 'Brand 4' p5 = 'Other'; id subj set c; run; title2 'Discrete Choice with Cross Effects, Mother Logit'; proc format; value zer 0 = ' 0' 1 = ' 1'; run; proc print data=coded(obs=5) label; var subj set c brand price; run; proc print data=coded(obs=5) label; var Brand:; format brand: zer5.2 brand brand.; run; proc print data=coded(obs=5) label; var p1B:; format p: zer5.2; id brand; run; proc print data=coded(obs=5) label; var p2B:; format p: zer5.2; id brand; run; proc print data=coded(obs=5) label; var p3B:; format p: zer5.2; id brand; run; proc print data=coded(obs=5) label; var p4B:; format p: zer5.2; id brand; run; proc print data=coded(obs=5) label; var p5B:; format p: zer5.2; id brand; run; %put &_trgind; proc phreg data=coded brief; model c*c(2) = &_trgind / ties=breslow; strata subj set; run; proc transreg design data=price nozeroconstant norestoremissing; model class(brand / zero='Other' separators='' ' ') | identity(price) identity(p1-p4) * class(brand / zero='Other' separators='' ' on ') / lprefix=0; output out=coded(drop=_type_ _name_ intercept); label price = 'Price' p1 = 'Brand 1' p2 = 'Brand 2' p3 = 'Brand 3' p4 = 'Brand 4'; id subj set c; run; proc transreg design data=price nozeroconstant norestoremissing; model class(brand / zero='Other' separators='' ' ') identity(p1-p4) * class(brand / zero='Other' separators='' ' on ') / lprefix=0; output out=coded(drop=_type_ _name_ intercept); label price = 'Price' p1 = 'Brand 1' p2 = 'Brand 2' p3 = 'Brand 3' p4 = 'Brand 4'; id subj set c; run; title 'Brand Choice Example, Multinomial Logit Model'; title2 'Aggregate Data'; %let m = 5; /* Number of Brands in Each Choice Set */ /* (including Other) */ proc format; value brand 1 = 'Brand 1' 2 = 'Brand 2' 3 = 'Brand 3' 4 = 'Brand 4' 5 = 'Other'; run; data price2; array p[&m] p1-p&m; /* Prices for the Brands */ array f[&m] f1-f&m; /* Frequency of Choice */ input p1-p&m f1-f&m; keep set price brand freq c p1-p&m; * Store choice set number to stratify; Set = _n_; do Brand = 1 to &m; Price = p[brand]; * Output first choice: c=1, unchosen: c=2; Freq = f[brand]; c = 1; output; * Output number of times brand was not chosen.; freq = sum(of f1-f&m) - freq; c = 2; output; end; format brand brand.; datalines; 3.99 5.99 3.99 5.99 4.99 4 29 16 42 9 5.99 5.99 5.99 5.99 4.99 12 19 22 33 14 5.99 5.99 3.99 3.99 4.99 34 26 8 27 5 5.99 3.99 5.99 3.99 4.99 13 37 15 27 8 5.99 3.99 3.99 5.99 4.99 49 1 9 37 4 3.99 5.99 5.99 3.99 4.99 31 12 6 18 33 3.99 3.99 5.99 5.99 4.99 37 10 5 35 13 3.99 3.99 3.99 3.99 4.99 16 14 5 51 14 ; proc print data=price2(obs=10); var set c freq price brand; run; proc transreg design data=price2 nozeroconstant norestoremissing; model class(brand / zero=none) identity(price) / lprefix=0; output out=coded(drop=_type_ _name_ intercept); label price = 'Price'; id freq set c; run; proc phreg data=coded; title2 'Discrete Choice with Common Price Effect, Aggregate Data'; model c*c(2) = &_trgind / ties=breslow; strata set; freq freq; run; proc transreg design data=price2 nozeroconstant norestoremissing; model class(brand / zero=none separators='' ' ') | identity(price) / lprefix=0; output out=coded(drop=_type_ _name_ intercept); label price = 'Price'; id freq set c; run; proc phreg data=coded; title2 'Discrete Choice with Brand by Price Effects, Aggregate Data'; model c*c(2) = &_trgind / ties=breslow; strata set; freq freq; run; ************** Begin Food Product Example Code **************; options ls=80 ps=60 nonumber nodate; title; title 'Consumer Food Product Example'; %macro resmac; navail = (x1 < 4) + (x2 < 4) + (x5 < 3) + (x6 < 3) + (x8 < 3); if (navail < 2) | (navail > 4) then bad = abs(navail - 3); else bad = 0; %mend; %mktex( 4 4 2 2 3 3 2 3, n=26, interact=x2*x3 x2*x4 x3*x4 x6*x7, restrictions=resmac, seed=377, outr=sasuser.Entree_LinDes1 ) /* proc gplot; title h=1 'Consumer Food Product Example'; title2 h=1 'Maximum D-Efficiency Found Over Time'; plot e * n / vaxis=axis1; symbol i=join; axis1 order=(0 to 90 by 10); run; quit; */ * Override maxtime=, make macro run faster so code can be tested; %let mktexopts=maxtime=0; title 'Consumer Food Product Example'; %macro resmac; navail = (x1 < 4) + (x2 < 4) + (x5 < 3) + (x6 < 3) + (x8 < 3); if (navail < 2) | (navail > 4) then bad = abs(navail - 3); else bad = 0; %mend; %mktex( 4 4 2 2 3 3 2 3, n=26, interact=x2*x3 x2*x4 x3*x4 x6*x7, restrictions=resmac, seed=151, maxtime=300 300 60, maxiter=10000 ) * Restore normal options; %let mktexopts=; %mkteval(data=sasuser.Entree_LinDes1); %mktruns( 4 4 2 2 3 3 2 3 ) %mktruns( 4 4 2 2 3 3 2 3, interact=x2*x3 x2*x4 x3*x4 x6*x7 ) title 'Consumer Food Product Example'; %macro resmac; navail = (x1 < 4) + (x2 < 4) + (x5 < 3) + (x6 < 3) + (x8 < 3); if (navail < 2) | (navail > 4) then bad = abs(navail - 3); else bad = 0; %mend; data mat; input a b c; datalines; 1 1 . 2 3 4 5 5 . 6 7 . 8 8 . ; %mktex( 4 4 2 2 3 3 2 3, n=36, order=matrix=mat, interact=x2*x3 x2*x4 x3*x4 x6*x7, restrictions=resmac, seed=377, outr=sasuser.Entree_LinDes2 ) %mkteval; data mat; input a b c; datalines; 1 1 . 2 3 4 5 5 . 6 7 . 8 8 . 1 1 1 2 2 2 3 3 3 4 4 4 5 5 5 6 6 6 7 7 7 8 8 8 ; %mktex( 4 4 2 2 3 3 2 3, n=36, order=matrix=mat, interact=x2*x3 x2*x4 x3*x4 x6*x7, restrictions=resmac, seed=368, outr=sasuser.Entree_LinDes3, balance=2, mintry=5 * n ) * Due to machine differences, you may not get the same design if you run * the step above, so here is the design that was used in the book; data sasuser.Entree_LinDes3; input x1-x8 @@; datalines; 4 2 2 1 1 1 2 2 1 3 1 1 1 3 1 1 1 3 2 2 3 2 2 1 1 2 1 2 3 1 2 1 4 1 1 1 2 3 2 1 3 4 1 2 2 3 1 3 3 1 2 2 1 3 2 1 2 4 1 1 3 1 2 3 2 4 2 2 3 1 1 3 2 2 2 2 1 2 1 3 4 3 1 2 2 2 1 1 1 2 2 1 3 3 2 3 2 1 2 1 3 3 1 2 4 3 1 1 3 2 2 3 2 3 1 2 1 1 1 3 3 2 1 1 3 2 1 2 1 4 1 2 1 2 1 2 1 1 1 2 1 3 1 3 3 2 2 1 3 1 1 1 4 3 2 1 1 1 1 2 1 1 2 1 2 2 2 3 4 2 1 2 1 3 2 3 3 1 1 1 1 1 2 3 4 4 2 1 3 2 1 1 3 3 2 1 2 2 1 3 4 3 2 2 3 3 1 2 1 4 1 1 2 1 1 2 2 2 1 1 2 3 1 1 4 4 1 2 1 2 2 1 1 4 2 2 2 1 2 2 3 4 2 1 1 2 2 2 2 1 1 2 3 2 2 2 2 3 2 1 2 3 2 1 4 1 2 2 2 1 2 3 3 3 1 2 3 3 2 2 3 2 2 2 2 3 1 2 ; %mkteval; %mktex( 4 4 2 2 3 3 2 3, n=36, interact=x2*x3 x2*x4 x3*x4 x6*x7, restrictions=resmac, seed=472, outr=sasuser.Entree_LinDes4, balance=1, mintry=5 * n ) %mkteval; %macro evaleff(where); data desv / view=desv; set sasuser.Entree_LinDes3(where=(&where)); run; proc optex data=desv; class x3 x4 x7 / param=orthref; model x1-x8 x2*x3 x2*x4 x3*x4 x6*x7; generate method=sequential initdesign=desv; run; quit; %mkteval(data=desv) %mend; %evaleff(x1 ne 4) %evaleff(x2 ne 4) %evaleff(x5 ne 3) %evaleff(x6 ne 3) %evaleff(x8 ne 3) data temp; set sasuser.Entree_LinDes3; y = 1; run; proc glm data=temp; model y = x1-x8 x2*x3 x2*x4 x3*x4 x6*x7 / e aliasing; run; quit; proc glm data=temp; model y = x1-x8 x2*x3 x2*x4 x3*x4 x6*x7 x1|x2|x3|x4|x5|x6|x7|x8@3 / e aliasing; run; quit; %mktblock(data=sasuser.Entree_LinDes3, out=sasuser.Entree_LinDes, nblocks=2, seed=448) * Due to machine differences, you may not get the same design if you run * the step above, so here is the design that was used in the book; data sasuser.Entree_LinDes; input Block Run x1-x8 @@; datalines; 1 1 1 3 1 1 1 3 1 1 1 2 3 1 2 2 1 3 2 1 1 3 2 4 2 2 3 1 1 3 1 4 4 3 1 2 2 2 1 1 1 5 1 2 2 1 3 3 2 3 1 6 4 3 1 1 3 2 2 3 1 7 2 3 1 2 1 1 1 3 1 8 1 1 2 1 2 2 2 3 1 9 4 2 1 2 1 3 2 3 1 10 3 1 1 1 1 1 2 3 1 11 4 4 2 1 3 2 1 1 1 12 4 3 2 2 3 3 1 2 1 13 1 4 1 1 2 1 1 2 1 14 2 2 1 1 2 3 1 1 1 15 1 4 2 2 2 1 2 2 1 16 3 4 2 1 1 2 2 2 1 17 2 1 1 2 3 2 2 2 1 18 3 2 2 2 2 3 1 2 2 1 4 2 2 1 1 1 2 2 2 2 1 3 2 2 3 2 2 1 2 3 1 2 1 2 3 1 2 1 2 4 4 1 1 1 2 3 2 1 2 5 3 4 1 2 2 3 1 3 2 6 2 4 1 1 3 1 2 3 2 7 2 2 2 2 1 2 1 3 2 8 2 1 2 1 3 3 1 2 2 9 3 2 1 1 3 2 1 2 2 10 1 4 1 2 1 2 1 2 2 11 1 1 1 2 1 3 1 3 2 12 3 2 2 1 3 1 1 1 2 13 4 3 2 1 1 1 1 2 2 14 3 3 2 1 2 2 1 3 2 15 4 4 1 2 1 2 2 1 2 16 2 3 2 1 2 3 2 1 2 17 4 1 2 2 2 1 2 3 2 18 3 3 1 2 3 3 2 2 ; proc format; value yn 1 = 'No' 2 = 'Talker'; value micro 1 = 'Micro' 2 = 'Stove'; run; data key; missing N; input x1-x8; format x1 x2 x5 x6 x8 dollar5.2 x4 yn. x3 x7 micro.; label x1 = 'Client Brand' x2 = 'Client Line Extension' x3 = 'Client Micro/Stove' x4 = 'Shelf Talker' x5 = 'Regional Brand' x6 = 'Private Label' x7 = 'Private Micro/Stove' x8 = 'National Competitor'; datalines; 1.29 1.39 1 1 1.99 1.49 1 1.99 1.69 1.89 2 2 2.49 2.29 2 2.39 2.09 2.39 . . N N . N N N . . . . . . ; %mktlab(data=sasuser.Entree_LinDes, key=key) proc sort out=sasuser.Entree_LinDesLab(drop=run); by block x4; run; proc print label; id block x4; by block x4; run; proc print data=sasuser.Entree_LinDesLab; format _numeric_; run; data key; input Brand $ 1-10 (Price Micro Shelf) ($); datalines; Client x1 . . Extension x2 x3 x4 Regional x5 . . Private x6 x7 . National x8 . . None . . . ; %mktroll(design=sasuser.Entree_LinDesLab, key=key, alt=brand, out=rolled, keep=x1 x2 x5 x6 x8) proc print data=sasuser.Entree_LinDesLab(obs=2); run; proc print data=rolled(obs=12); format price dollar5.2 shelf yn. micro micro.; id set; by set; run; data sasuser.Entree_ChDes(drop=i); set rolled; array x[6] price x1 -- x8; array a[5] a1 a2 a5 a6 a8; if nmiss(micro) then micro = 2; /* stove if not a factor in alt */ if nmiss(shelf) then shelf = 1; /* not talker if not a factor in alt */ a1 = -3 * nmiss(x1) + n(x1); /* alt1: -3 - not avail, 1 - avail */ a2 = -3 * nmiss(x2) + n(x2); /* alt2: -3 - not avail, 1 - avail */ a5 = -2 * nmiss(x5) + n(x5); /* alt3: -2 - not avail, 1 - avail */ a6 = -2 * nmiss(x6) + n(x6); /* alt4: -2 - not avail, 1 - avail */ a8 = -2 * nmiss(x8) + n(x8); /* alt5: -2 - not avail, 1 - avail */ i = mod(_n_ - 1, 6) + 1; /* alternative number */ if i le 5 then a[i] = 0; /* 0 effect of an alt on itself */ do i = 1 to 6; if nmiss(x[i]) then x[i] = 0; end; /* missing price -> 0 */ w = brand eq 'None' or price ne 0; /* 1 - avail, 0 not avail*/ format price dollar5.2 shelf yn. micro micro.; label x1 = 'CE, Client' a1 = 'AE, Client' x2 = 'CE, Extension' a2 = 'AE, Extension' x5 = 'CE, Regional' a5 = 'AE, Regional' x6 = 'CE, Private' a6 = 'AE, Private' x8 = 'CE, National' a8 = 'AE, National'; run; proc print data=sasuser.Entree_ChDes(obs=18); by set; id set; run; %choiceff(data=sasuser.Entree_ChDes, model=class(brand / zero='None') class(brand / zero='None' separators='' ' ') * identity(price) class(shelf micro / lprefix=5 0 zero='No' 'Stove') identity(x1 x2 x5 x6 x8) * class(brand / zero='None' separators=' ' ' on ') identity(a1 a2 a5 a6 a8) * class(brand / zero='None' separators=' ' ' on ') / lprefix=0 order=data, nsets=36, nalts=6, weight=w, beta=zero, init=sasuser.Entree_ChDes(keep=set), intiter=0) proc print data=tmp_cand(obs=24) label; var Brand Price Shelf Micro; where w; run; proc print data=tmp_cand(obs=5) label; id Brand; var BrandClient -- BrandNational; where w; run; proc format; value zer 0 = ' 0'; run; proc print data=tmp_cand(obs=5) label; id Brand Price; var BrandClientPrice -- BrandNationalPrice; format BrandClientPrice -- BrandNationalPrice zer5.2; where w; run; proc print data=tmp_cand(obs=5) label; id Brand Price Shelf Micro; var shelftalker micromicro; where w; run; proc print data=tmp_cand(obs=4) label; id Brand Price; var x1Brand:; format x1Brand: zer5.2; where w; run; proc print data=tmp_cand(obs=4) label; id Brand Price; var x2Brand:; format x2Brand: zer5.2; where w; run; proc print data=tmp_cand(obs=4) label; id Brand Price; var x5Brand:; format x5Brand: zer5.2; where w; run; proc print data=tmp_cand(obs=4) label; id Brand Price; var x6Brand:; format x6Brand: zer5.2; where w; run; proc print data=tmp_cand(obs=4) label; id Brand Price; var x8Brand:; format x8Brand: zer5.2; where w; run; proc print data=tmp_cand(obs=4) label; id Brand Price; var a1Brand:; where w; run; proc print data=tmp_cand(obs=4) label; id Brand Price; var a2Brand:; where w; run; proc print data=tmp_cand(obs=4) label; id Brand Price; var a5Brand:; where w; run; proc print data=tmp_cand(obs=4) label; id Brand Price; var a6Brand:; where w; run; proc print data=tmp_cand(obs=4) label; id Brand Price; var a8Brand:; where w; run; %let m = 6; %let mm1 = %eval(&m - 1); %let n = 36; proc format; value yn 1 = 'No' 2 = 'Talker'; value micro 1 = 'Micro' 2 = 'Stove'; run; data _null_; array brands[&m] _temporary_ (5 7 1 2 3 -2); array u[&m]; array x[&mm1] x1 x2 x5 x6 x8; do rep = 1 to 300; if mod(rep, 2) then put; put rep 3. +2 @@; do j = 1 to &n; set sasuser.Entree_LinDesLab point=j; do brand = 1 to &m; u[brand] = brands[brand] + 2 * normal(17); end; do brand = 1 to &mm1; if n(x[brand]) then u[brand] + -x[brand]; else u[brand] = .; end; if n(u2) and x4 = 2 then u2 + 1; /* shelf talker */ if n(u2) and x3 = 1 then u2 + 1; /* microwave */ if n(u4) and x7 = 1 then u4 + 1; /* microwave */ * Choose the most preferred alternative.; m = max(of u1-u&m); do brand = 1 to &m; if n(u[brand]) then if abs(u[brand] - m) < 1e-4 then c = brand; end; put +(-1) c @@; end; end; stop; run; data results; input Subj (choose1-choose&n) (1.) @@; datalines; 1 222224155212222522221221222221212522 2 222225421242222122221212222221211322 3 212224521545222122221222221121112522 4 212125121212222122221222421221212522 5 222225125212222122521212222221212422 6 222125523112222122224221212111242522 7 222225121242222422221122221221112422 8 222225124212222122221222522221212422 9 122125121242222122221222222221242322 10 212125125212222122221211222221112522 11 222225121212222522221222222123212522 12 122124121212222422221222221221212522 13 122225125212222121221222222221212522 14 222214123142222122221222241221211322 15 222125121212222122221221221221212421 16 212124425212222422224112422123212522 17 212126525212222122524121421226212522 18 222225121212222111221222221121242622 19 222225111212222121221212222121212522 20 222225121212222122221222222223212421 21 222124111212225122221222222221212422 22 212224125212222122221212212221112422 23 122224425212222122224121422221211422 24 212226421212222121221222211121211522 25 122225121212222121221222222221212622 26 222124521212222522221222241521212522 27 222225421242122122221222222221252522 28 222225321212222322224221222221212322 29 122225421112222122221222422121211522 30 212124111242222122421222222221212522 31 222225125242232122521225222121212622 32 222225123112222122221222242223112522 33 212225121212222122221222222221252522 34 222225151212222522421122222121252522 35 112225123212222122224222522221242522 36 222225426212222122224222221121212522 37 212224115212222522221222221221212642 38 122215521212222112221222422221212522 39 222225125212222151221211222221112522 40 224225111112222122221222221221212442 41 222225121212222121221225221221112522 42 222125125512222121221222422221212522 43 222124525242222112421222421226212422 44 212124121212222122221122222221252422 45 222224121212222122521222222226212322 46 222125521112222321221211222221212522 47 122215121212222122221211522121212522 48 212114121212222122221122212221211422 49 212224415212222122226221222521112521 50 222215121214222521221222212121212522 51 122215124242222422521222222221212522 52 222125121262222522221212221121112522 53 222225121212222122224222221121212622 54 212225411215222122226221222221212522 55 222224121212222122224222221221212522 56 222115116212222122221222242221212522 57 222215421212222122521222221221252322 58 222224521242222122221222221221212522 59 122225421212222522221222222121242522 60 222224124212422122221112211111212422 61 222225121212222122421212222221211522 62 212224411212222122221215212211112422 63 222215125242122122221222225211211422 64 122224125212222112221222522221212525 65 122226521212222522224222222221252522 66 112224121212222151224222522221212422 67 122224111212222422221221222221212422 68 212125121242222122221221222221212522 69 222224125242222121524222222226212521 70 222224521242122122521122211511212522 71 522225123212222121224122212221212321 72 222224421212222122251251211221212422 73 212225121242222122221222221221112522 74 112224521212222522521522212221232522 75 222225421242225122221222212211212422 76 112114121212222122221222222221212522 77 222224121212222122221222422121252522 78 222225111212222122221221422221211322 79 112225421212222122221222221221212522 80 112225121212222122221222211221212422 81 222125121242222112224222212121252422 82 222225121212222122221121222123242522 83 222225123212222122221222212226212422 84 124245125242222422221222225121211522 85 122225121212422122221222222121212522 86 222124115242222122224222222221112522 87 214114121212222112221221222221242522 88 122225121212222122221112212221242522 89 212214111242222122221122222221112522 90 222225121212222122221222222221212522 91 212225111242222125221242211221152622 92 212225125212222122221125221221242422 93 222216126212222121221522222221252422 94 122225121212222121224222222121212322 95 222114521242222122221222212221212522 96 222125421212222122221222211521152522 97 222215121542222122221222222221212522 98 112245124212222122221112222221212522 99 212215121212222122221224221221212522 100 122214111212222121221512225221112622 101 212225425212125122221222221211212522 102 222225421212222422224222222121212522 103 222225411262222521224222212226212522 104 122225124242222622421222422221212522 105 112224121212222521221222222211212522 106 222214124212222121221222221221252522 107 222226116242222122221222212121212521 108 222124121212222422221122222221212521 109 222124125242222412224122421221212622 110 112124121212222122221222212121252422 111 212125121212222122221122422221211422 112 262125121212222122221222421221211622 113 222215325212222122221222222221212322 114 222424121212122512221121222221152522 115 122225124242122422221222221221112422 116 222215111212222122221222222221242522 117 222224121242222122521222222111212522 118 222225121212222122221121222121212422 119 122125125112222121221222221221252322 120 222215121212225122221221421226112522 121 122224121212222122224221222521212322 122 222224121242222522224222221211242522 123 222124125242122112321221215221212522 124 222225121215222122221222212121212422 125 222126125112222122221122222221212322 126 212114425212222512421122212221111322 127 222225115212222122221222222221211522 128 222224511212125121221222222221212322 129 222125113212222122221122221221212422 130 112215125212222122221225242221212422 131 222125121212222122221222421221212522 132 212226121212122122521152211221211522 133 122224125112222122521122242223212422 134 212124111212222122221121221221212322 135 122225121212222122221112221221212522 136 122225121212222122521214222221212522 137 222125424214222422221522222221212522 138 222225121212222122221222222121242522 139 222225121212222521224211222221212522 140 122115121242222122221222241221212522 141 222224321212222122221251221221212522 142 222224421212222122524222222211212522 143 112214124212222121221222221121212422 144 222225121112222122221222221121252522 145 122225421242222122221222221221212522 146 122224121212222422221221222221212422 147 222224421242222121221211212221212421 148 122125121242222122221222222121211422 149 222225524212222112221221221221211522 150 212225421212222512221221412121212521 151 222225111142122122521222212221212522 152 212126121212222622221222222221212522 153 222225423212225422224212222221262522 154 222215121212225111224222241221212422 155 222125111242222122221221222221211322 156 212124121212222122221222222221211322 157 212125125212222512221221221513212622 158 212224121212222122221122221221212522 159 222125521212222122221222212226211521 160 222125121212222121221211212251212422 161 212124121242222122221112212411212522 162 222124121212222422221222226221211521 163 122224124212122122224221222221212522 164 222224115212222122221222422141412521 165 122124111212222122224222222121112322 166 122125124242222122221222222221252522 167 212225424242222121221222221221212522 168 212224121212222522224222222221242542 169 222225421212222122221222221121211421 170 122224121242222122221222222221232522 171 222224121112222322221222222223112422 172 212124111212222122224221222221212522 173 212225121212222121221221412221212521 174 122224524212222121221222411221212522 175 222225115242122322221222222121212421 176 212224121212422622421212422121112522 177 122125111242222122221222525211212322 178 222225125212222122221221222221212522 179 222225111212225122224262221226212322 180 122225511242222122224222221221112422 181 222224521212222112224222212221212322 182 222225114242222122221212222221252321 183 222224121242222122221221211221242322 184 222215111112222111221224222226252322 185 222215514245222522521122212221242422 186 222215125212222122221222212221212422 187 222225113212222122221221231121211522 188 212225125212222121221222222121212322 189 122124121212422122221222211221212522 190 212225424212222121521142241221212421 191 222124121112222112221522212211252422 192 222116121212222421221221221523212422 193 122226521242122122221222212221212322 194 222216125242222422221122221221242322 195 212224121212222122221211222221212522 196 222124121212222122226222222221211342 197 112224121242222121221222242221212621 198 122215121212222122224221211211212522 199 212225421212222422221222212121212421 200 212124125212222121521222222221111522 201 222215521212222122224122222221212422 202 212225121212422122221222212221212522 203 112125121214222621221122212221252525 204 222224121242222522221222221211212522 205 212124121212222122221222222121212422 206 122225124213222122221211222221252322 207 222125111212222122221222422121212322 208 222125115212222122221122412221212522 209 222124121512222122221222211221212422 210 222224121242222122321222521221212422 211 222225425112422122224121221221212322 212 222224111242222121221222222221212521 213 222226121212222112221222222221212422 214 212125521212222421221122223123212422 215 222125125242222122221222211121242522 216 222135111212222422221222221121252322 217 222225121212222422224222223221112322 218 222224121242222122221222412221112321 219 222224123212222122221212221226242522 220 112224521212122122221222222121212421 221 212225123142222122221222222221112421 222 212124126212222125221221212221112522 223 212225151212222122221221221221212522 224 112225125212222122221222221221212522 225 222224424242222112224221522121212422 226 222226121212225422221122222221112441 227 512225123242122122221222222121212522 228 222125424242222122221112421221212522 229 112224124212222122221222222221212422 230 214226115212222122224212222221212521 231 222225111212222422221222212123212522 232 212224121242222122221122211221112522 233 212125111212225421221222221121212422 234 212225525212222122224222422221212522 235 222224125212222422221222221521412422 236 212225423212222621221224412221212622 237 222124111212225422221122212121212522 238 222225121142222522221224222221212522 239 212225421212122122221121211221112422 240 222225111212222112221122221221142522 241 212124125212222122221122221521252521 242 122225121212222122521222521121212422 243 212115121212222122221212421121212322 244 514125124242422122226122422221212322 245 122125121212222121221222422221252522 246 122224521212222422221122221211241522 247 212225121212222121221222221221212522 248 112124121212222122221222221221242522 249 112224121242222121221222221221211422 250 212214421242222121221222211221112322 251 222125421212222122224522222221211542 252 222224511242222111224222222211212522 253 222225125242222122421222222221212322 254 212124123212222422221222421221212422 255 222225121242122422521222222121242422 256 226124321212222122221122242221112522 257 222224521212222122221222212221211322 258 212225125242222122221122222121212522 259 222224121212222112221222222221242422 260 222224111242422122221222221221212322 261 222224121112122422221222222211212522 262 212125551212222122224222422221242522 263 222225111212222122224215221221232422 264 212225121212222122221221221111242522 265 122226121212222122221221211121212622 266 112224121212222122221212225221212622 267 122124121212222122221222422221252522 268 222225521212222622221122221221242522 269 122224521212422122221221222221212521 270 212225121212222112221122322221212522 271 222125521212222422521212222121212522 272 122225121212122122221222212121212422 273 222115124212222122224222542221212522 274 112215325242222122224226422241212322 275 212225121212222122221112222221211322 276 222126121242222122231225222221212422 277 122224121242222122221224221221211522 278 222125521242222122221222222221212422 279 222124111212222522521221211221212522 280 122125121242222122251122222221212522 281 212224524112122122221222222221212522 282 212225425212222122421221422221212422 283 222226121242225122251222421221212522 284 222225121212222122221122222221252322 285 122226125212222622221122212123161422 286 222224121212222122221225222221212521 287 512126121312222121251221222251212522 288 122125521212222412221221221121212522 289 222225421212222125221221241221212542 290 212224121112122122221222222223212521 291 222126121212222121221222521221412522 292 122224125242225512221221222221212422 293 512224525242122312221222522221252522 294 522225121242222122221524212221212522 295 222114121212122522221222221221212421 296 222424123242222122221122221121212622 297 222225521212222422224222522121151622 298 222224121242122422221222512221212522 299 112225121212122121521222212211212622 300 122225123242122122221211222123212322 ; %mktmerge(design=sasuser.Entree_ChDes, data=results, out=res2, nsets=&n, nalts=&m, setvars=choose1-choose&n) proc print data=res2(obs=12); id subj set; by subj set; run; proc summary data=res2 nway; class set brand price shelf micro x1 x2 x5 x6 x8 a1 a2 a5 a6 a8 c; output out=agg(drop=_type_); where w; /* exclude unavailable, w = 0 */ run; proc print; where set = 1; run; proc transreg data=agg design=5000 nozeroconstant norestoremissing; model class(brand / zero='None') class(brand / zero='None' separators='' ' ') * identity(price) class(shelf micro / lprefix=5 0 zero='No' 'Stove') identity(x1 x2 x5 x6 x8) * class(brand / zero='None' separators=' ' ' on ') identity(a1 a2 a5 a6 a8) * class(brand / zero='None' separators=' ' ' on ') / lprefix=0; output out=coded(drop=_type_ _name_ intercept); id set c _freq_; label shelf = 'Shelf Talker' micro = 'Microwave'; run; proc phreg data=coded; strata set; model c*c(2) = &_trgind / ties=breslow; freq _freq_; run; proc transreg data=agg design=5000 nozeroconstant norestoremissing; model class(brand / zero='None') class(brand / zero='None' separators='' ' ') * identity(price) class(shelf micro / lprefix=5 0 zero='No' 'Stove') / lprefix=0; output out=coded(drop=_type_ _name_ intercept); id set c _freq_; label shelf = 'Shelf Talker' micro = 'Microwave'; run; proc phreg data=coded; strata set; model c*c(2) = &_trgind / ties=breslow; freq _freq_; run; data results; input Subj (choose1-choose&n) (1.) Age Income; datalines; 1 222224155212222522221221222221212522 33 109 2 222225421242222122221212222221211322 56 117 3 212224521545222122221222221121112522 56 78 4 212125121212222122221222421221212522 57 107 5 222225125212222122521212222221212422 40 115 6 222125523112222122224221212111242522 55 80 7 222225121242222422221122221221112422 56 109 8 222225124212222122221222522221212422 52 122 9 122125121242222122221222222221242322 36 117 10 212125125212222122221211222221112522 41 101 11 222225121212222522221222222123212522 53 123 12 122124121212222422221222221221212522 50 114 13 122225125212222121221222222221212522 64 120 14 222214123142222122221222241221211322 41 94 15 222125121212222122221221221221212421 51 113 16 212124425212222422224112422123212522 24 70 17 212126525212222122524121421226212522 61 63 18 222225121212222111221222221121242622 57 108 19 222225111212222121221212222121212522 58 113 20 222225121212222122221222222223212421 46 128 21 222124111212225122221222222221212422 57 114 22 212224125212222122221212212221112422 60 108 23 122224425212222122224121422221211422 61 86 24 212226421212222121221222211121211522 20 95 25 122225121212222121221222222221212622 35 126 26 222124521212222522221222241521212522 61 91 27 222225421242122122221222222221252522 40 116 28 222225321212222322224221222221212322 26 121 29 122225421112222122221222422121211522 24 96 30 212124111242222122421222222221212522 49 102 31 222225125242232122521225222121212622 24 88 32 222225123112222122221222242223112522 45 106 33 212225121212222122221222222221252522 43 127 34 222225151212222522421122222121252522 43 91 35 112225123212222122224222522221242522 26 99 36 222225426212222122224222221121212522 24 111 37 212224115212222522221222221221212642 53 98 38 122215521212222112221222422221212522 34 102 39 222225125212222151221211222221112522 54 95 40 224225111112222122221222221221212442 28 96 41 222225121212222121221225221221112522 27 107 42 222125125512222121221222422221212522 24 96 43 222124525242222112421222421226212422 24 76 44 212124121212222122221122222221252422 44 114 45 222224121212222122521222222226212322 34 124 46 222125521112222321221211222221212522 64 97 47 122215121212222122221211522121212522 36 94 48 212114121212222122221122212221211422 63 100 49 212224415212222122226221222521112521 46 79 50 222215121214222521221222212121212522 21 95 51 122215124242222422521222222221212522 30 98 52 222125121262222522221212221121112522 49 96 53 222225121212222122224222221121212622 58 121 54 212225411215222122226221222221212522 59 97 55 222224121212222122224222221221212522 28 127 56 222115116212222122221222242221212522 38 103 57 222215421212222122521222221221252322 21 105 58 222224521242222122221222221221212522 28 122 59 122225421212222522221222222121242522 24 110 60 222224124212422122221112211111212422 36 83 61 222225121212222122421212222221211522 50 114 62 212224411212222122221215212211112422 38 83 63 222215125242122122221222225211211422 27 90 64 122224125212222112221222522221212525 65 96 65 122226521212222522224222222221252522 45 111 66 112224121212222151224222522221212422 25 90 67 122224111212222422221221222221212422 48 114 68 212125121242222122221221222221212522 65 114 69 222224125242222121524222222226212521 53 93 70 222224521242122122521122211511212522 30 72 71 522225123212222121224122212221212321 60 93 72 222224421212222122251251211221212422 34 90 73 212225121242222122221222221221112522 63 114 74 112224521212222522521522212221232522 43 81 75 222225421242225122221222212211212422 43 103 76 112114121212222122221222222221212522 64 113 77 222224121212222122221222422121252522 35 115 78 222225111212222122221221422221211322 22 109 79 112225421212222122221222221221212522 62 114 80 112225121212222122221222211221212422 60 113 81 222125121242222112224222212121252422 32 97 82 222225121212222122221121222123242522 64 110 83 222225123212222122221222212226212422 33 124 84 124245125242222422221222225121211522 23 68 85 122225121212422122221222222121212522 39 114 86 222124115242222122224222222221112522 51 103 87 214114121212222112221221222221242522 26 89 88 122225121212222122221112212221242522 35 107 89 212214111242222122221122222221112522 21 101 90 222225121212222122221222222221212522 34 139 91 212225111242222125221242211221152622 34 73 92 212225125212222122221125221221242422 60 97 93 222216126212222121221522222221252422 58 105 94 122225121212222121224222222121212322 32 115 95 222114521242222122221222212221212522 60 109 96 222125421212222122221222211521152522 46 90 97 222215121542222122221222222221212522 63 115 98 112245124212222122221112222221212522 32 96 99 212215121212222122221224221221212522 60 107 100 122214111212222121221512225221112622 65 77 101 212225425212125122221222221211212522 53 90 102 222225421212222422224222222121212522 61 116 103 222225411262222521224222212226212522 26 94 104 122225124242222622421222422221212522 59 94 105 112224121212222521221222222211212522 26 107 106 222214124212222121221222221221252522 55 109 107 222226116242222122221222212121212521 40 104 108 222124121212222422221122222221212521 36 114 109 222124125242222412224122421221212622 56 81 110 112124121212222122221222212121252422 33 101 111 212125121212222122221122422221211422 59 101 112 262125121212222122221222421221211622 27 97 113 222215325212222122221222222221212322 47 124 114 222424121212122512221121222221152522 43 84 115 122225124242122422221222221221112422 61 97 116 222215111212222122221222222221242522 26 120 117 222224121242222122521222222111212522 65 109 118 222225121212222122221121222121212422 33 119 119 122125125112222121221222221221252322 22 97 120 222215121212225122221221421226112522 28 84 121 122224121212222122224221222521212322 52 110 122 222224121242222522224222221211242522 47 105 123 222124125242122112321221215221212522 29 73 124 222225121215222122221222212121212422 64 114 125 222126125112222122221122222221212322 44 116 126 212114425212222512421122212221111322 49 61 127 222225115212222122221222222221211522 46 120 128 222224511212125121221222222221212322 64 103 129 222125113212222122221122221221212422 48 109 130 112215125212222122221225242221212422 47 90 131 222125121212222122221222421221212522 56 114 132 212226121212122122521152211221211522 59 77 133 122224125112222122521122242223212422 23 87 134 212124111212222122221121221221212322 30 101 135 122225121212222122221112221221212522 35 113 136 122225121212222122521214222221212522 43 102 137 222125424214222422221522222221212522 43 93 138 222225121212222122221222222121242522 49 127 139 222225121212222521224211222221212522 35 108 140 122115121242222122221222241221212522 45 96 141 222224321212222122221251221221212522 57 110 142 222224421212222122524222222211212522 33 110 143 112214124212222121221222221121212422 35 95 144 222225121112222122221222221121252522 36 114 145 122225421242222122221222221221212522 23 115 146 122224121212222422221221222221212422 39 121 147 222224421242222121221211212221212421 51 96 148 122125121242222122221222222121211422 56 108 149 222225524212222112221221221221211522 40 102 150 212225421212222512221221412121212521 56 77 151 222225111142122122521222212221212522 34 95 152 212126121212222622221222222221212522 39 122 153 222225423212225422224212222221262522 45 96 154 222215121212225111224222241221212422 21 84 155 222125111242222122221221222221211322 46 109 156 212124121212222122221222222221211322 39 121 157 212125125212222512221221221513212622 61 74 158 212224121212222122221122221221212522 40 119 159 222125521212222122221222212226211521 39 103 160 222125121212222121221211212251212422 36 94 161 212124121242222122221112212411212522 26 83 162 222124121212222422221222226221211521 42 103 163 122224124212122122224221222221212522 24 109 164 222224115212222122221222422141412521 32 79 165 122124111212222122224222222121112322 41 103 166 122125124242222122221222222221252522 64 110 167 212225424242222121221222221221212522 59 103 168 212224121212222522224222222221242542 28 105 169 222225421212222122221222221121211421 36 108 170 122224121242222122221222222221232522 52 123 171 222224121112222322221222222223112422 47 118 172 212124111212222122224221222221212522 33 108 173 212225121212222121221221412221212521 35 94 174 122224524212222121221222411221212522 62 90 175 222225115242122322221222222121212421 42 98 176 212224121212422622421212422121112522 23 73 177 122125111242222122221222525211212322 46 85 178 222225125212222122221221222221212522 21 127 179 222225111212225122224262221226212322 26 94 180 122225511242222122224222221221112422 31 97 181 222224521212222112224222212221212322 62 117 182 222225114242222122221212222221252321 56 105 183 222224121242222122221221211221242322 48 111 184 222215111112222111221224222226252322 45 86 185 222215514245222522521122212221242422 22 62 186 222215125212222122221222212221212422 51 120 187 222225113212222122221221231121211522 63 92 188 212225125212222121221222222121212322 42 115 189 122124121212422122221222211221212522 64 101 190 212225424212222121521142241221212421 29 61 191 222124121112222112221522212211252422 46 89 192 222116121212222421221221221523212422 28 86 193 122226521242122122221222212221212322 34 111 194 222216125242222422221122221221242322 48 100 195 212224121212222122221211222221212522 57 119 196 222124121212222122226222222221211342 28 111 197 112224121242222121221222242221212621 58 97 198 122215121212222122224221211211212522 24 94 199 212225421212222422221222212121212421 57 102 200 212124125212222121521222222221111522 51 89 201 222215521212222122224122222221212422 63 115 202 212225121212422122221222212221212522 41 114 203 112125121214222621221122212221252525 34 66 204 222224121242222522221222221211212522 29 115 205 212124121212222122221222222121212422 37 120 206 122225124213222122221211222221252322 60 100 207 222125111212222122221222422121212322 51 109 208 222125115212222122221122412221212522 63 95 209 222124121512222122221222211221212422 61 108 210 222224121242222122321222521221212422 60 105 211 222225425112422122224121221221212322 47 87 212 222224111242222121221222222221212521 56 114 213 222226121212222112221222222221212422 25 133 214 212125521212222421221122223123212422 37 81 215 222125125242222122221222211121242522 32 97 216 222135111212222422221222221121252322 54 93 217 222225121212222422224222223221112322 26 113 218 222224121242222122221222412221112321 43 104 219 222224123212222122221212221226242522 54 112 220 112224521212122122221222222121212421 32 101 221 212225123142222122221222222221112421 29 104 222 212124126212222125221221212221112522 56 90 223 212225151212222122221221221221212522 41 107 224 112225125212222122221222221221212522 23 114 225 222224424242222112224221522121212422 50 87 226 222226121212225422221122222221112441 40 91 227 512225123242122122221222222121212522 23 98 228 222125424242222122221112421221212522 62 85 229 112224124212222122221222222221212422 64 121 230 214226115212222122224212222221212521 37 91 231 222225111212222422221222212123212522 38 110 232 212224121242222122221122211221112522 46 101 233 212125111212225421221222221121212422 43 83 234 212225525212222122224222422221212522 54 104 235 222224125212222422221222221521412422 40 98 236 212225423212222621221224412221212622 27 83 237 222124111212225422221122212121212522 45 89 238 222225121142222522221224222221212522 61 110 239 212225421212122122221121211221112422 31 88 240 222225111212222112221122221221142522 29 101 241 212124125212222122221122221521252521 31 83 242 122225121212222122521222521121212422 46 95 243 212115121212222122221212421121212322 52 89 244 514125124242422122226122422221212322 41 59 245 122125121212222121221222422221252522 60 102 246 122224521212222422221122221211241522 39 90 247 212225121212222121221222221221212522 33 119 248 112124121212222122221222221221242522 27 108 249 112224121242222121221222221221211422 47 101 250 212214421242222121221222211221112322 57 91 251 222125421212222122224522222221211542 40 92 252 222224511242222111224222222211212522 26 97 253 222225125242222122421222222221212322 35 118 254 212124123212222422221222421221212422 27 99 255 222225121242122422521222222121242422 35 98 256 226124321212222122221122242221112522 33 93 257 222224521212222122221222212221211322 43 122 258 212225125242222122221122222121212522 20 108 259 222224121212222112221222222221242422 36 127 260 222224111242422122221222221221212322 62 111 261 222224121112122422221222222211212522 20 114 262 212125551212222122224222422221242522 47 86 263 222225111212222122224215221221232422 46 98 264 212225121212222122221221221111242522 38 101 265 122226121212222122221221211121212622 48 108 266 112224121212222122221212225221212622 50 108 267 122124121212222122221222422221252522 22 109 268 222225521212222622221122221221242522 28 110 269 122224521212422122221221222221212521 48 102 270 212225121212222112221122322221212522 47 109 271 222125521212222422521212222121212522 47 96 272 122225121212122122221222212121212422 52 113 273 222115124212222122224222542221212522 35 92 274 112215325242222122224226422241212322 49 66 275 212225121212222122221112222221211322 42 114 276 222126121242222122231225222221212422 37 106 277 122224121242222122221224221221211522 45 102 278 222125521242222122221222222221212422 49 122 279 222124111212222522521221211221212522 49 89 280 122125121242222122251122222221212522 33 102 281 212224524112122122221222222221212522 58 109 282 212225425212222122421221422221212422 64 92 283 222226121242225122251222421221212522 21 92 284 222225121212222122221122222221252322 46 128 285 122226125212222622221122212123161422 38 82 286 222224121212222122221225222221212521 38 120 287 512126121312222121251221222251212522 62 67 288 122125521212222412221221221121212522 40 89 289 222225421212222125221221241221212542 28 85 290 212224121112122122221222222223212521 64 109 291 222126121212222121221222521221412522 42 96 292 122224125242225512221221222221212422 55 92 293 512224525242122312221222522221252522 37 70 294 522225121242222122221524212221212522 33 91 295 222114121212122522221222221221212421 56 101 296 222424123242222122221122221121212622 41 99 297 222225521212222422224222522121151622 23 87 298 222224121242122422221222512221212522 50 103 299 112225121212122121521222212211212622 41 89 300 122225123242122122221211222123212322 38 95 ; %mktmerge(design=sasuser.Entree_ChDes(drop=x1--x8 a1--a8), data=results, out=res2, nsets=&n, nalts=&m, setvars=choose1-choose&n) proc print data=res2; by subj set; id subj set; where (subj = 1 and set = 1) or (subj = 2 and set = 2) or (subj = 3 and set = 3) or (subj = 300 and set = 36); run; proc transreg data=res2 design=5000 nozeroconstant norestoremissing; model class(brand / zero='None') identity(age income) * class(brand / zero='None' separators='' ', ') class(brand / zero='None' separators='' ' ') * identity(price) class(shelf micro / lprefix=5 0 zero='No' 'Stove') / lprefix=0 order=data; output out=code(drop=_type_ _name_ intercept); id subj set c w; label shelf = 'Shelf Talker' micro = 'Microwave'; run; data coded(drop=w); set code; where w; run; /* exclude unavailable */ proc print data=coded(obs=4) label; id brand price; var BrandClient -- BrandPrivate Shelf Micro c; run; proc print data=coded(obs=4 drop=Age) label; id brand price; var Age:; run; proc print data=coded(obs=4 drop=Income) label; id brand price; var Income:; run; proc print data=coded(obs=4) label; id brand price; var BrandClientPrice -- BrandPrivatePrice; format BrandClientPrice -- BrandPrivatePrice best4.; run; proc phreg data=coded brief; model c*c(2) = &_trgind / ties=breslow; strata subj set; run; ************ Begin Prescription Drug Example Code ***********; options ls=80 ps=60 nonumber nodate; title; title 'Allocation of Prescription Drugs'; %mktruns( 3 ** 10 ) %let nalts = 10; %mktex(3 ** &nalts 3, n=27, seed=396) * Due to machine differences, you may not get the same design if you run * the step above, so here is the design that was used in the book; data randomized; input x1-x11 @@; datalines; 3 3 2 3 2 3 2 1 2 1 1 2 3 2 1 3 2 1 3 2 2 2 2 3 3 3 2 1 2 2 3 2 3 1 1 2 1 2 3 3 3 3 1 3 3 2 2 1 1 1 2 3 1 3 1 1 3 1 3 2 2 2 3 1 3 2 3 1 2 2 3 2 2 2 3 2 1 1 1 1 2 3 1 2 1 2 1 2 3 1 3 1 2 1 3 1 1 2 2 3 1 1 3 1 3 1 3 2 2 3 3 2 1 2 2 2 1 1 3 3 3 1 2 1 1 1 3 2 2 3 2 2 2 1 2 3 1 1 1 1 3 3 2 1 2 2 3 3 2 3 1 1 2 3 3 2 3 3 3 3 3 2 2 3 2 2 2 1 3 3 1 3 3 3 1 1 3 3 1 1 3 1 1 2 1 1 3 1 1 3 3 1 2 1 2 1 1 1 1 3 2 2 1 1 3 2 2 3 3 3 3 3 2 1 2 3 3 3 1 2 1 3 3 1 3 3 1 1 3 3 1 2 1 3 2 3 3 2 3 1 3 3 1 2 3 2 2 1 1 3 2 2 1 2 3 1 2 1 3 3 1 1 2 1 2 1 1 1 2 2 3 2 2 3 1 2 2 2 2 2 3 1 2 1 1 2 2 2 3 1 1 2 2 1 2 1 3 ; data key(drop=i); input Block Brand1; array Brand[10]; do i = 2 to 10; brand[i] = brand1; end; format brand: dollar4.; datalines; 1 50 2 75 3 100 ; proc print; run; %mktlab(key=key); proc sort out=sasuser.DrugAllo_LinDes; by block; run; proc print; id block; by block; run; %mkteval(blocks=block) data results(drop=i s n sub); length Block Subject Set 8; do sub = 1 to 100; do Block = 1 to 3; Subject + 1; do s = 1 to 9; array Freq[&nalts]; do i = 1 to &nalts; freq[i] = 0; end; if uniform(7) > 0.01 then do until(sum(of freq1-freq&nalts) = 10); freq[3] = 5 * (uniform(7) > 0.3); n = max(1, min(&nalts, round(abs(5 * normal(7))))); do i = 1 to n; freq[ceil(&nalts * uniform(7))] + round(abs(4 * normal(7))); end; n = max(1, sum(of freq1-freq&nalts)); do i = 1 to &nalts; freq[i] = round(10 * freq[i] / n); end; end; Set = (block - 1) * 9 + s; output; end; end; end; run; data _null_; set results; put Block 1. Subject 4. Set 2. @9 (freq1-freq&nalts) (2.); if _n_ = 11 then stop; run; data allocs(keep=block set brand count); set results; array freq[&nalts]; * Handle the &nalts alternatives; do b = 1 to &nalts; Brand = 'Brand ' || put(b, 2.); Count = freq[b]; output; end; * Constant alt choice is implied if nothing else is chosen. brand = ' ' is used to flag the constant alternative.; brand = ' '; count = 10 * (sum(of freq:) = 0); output; run; proc print data=results(obs=3) label noobs; run; proc print data=allocs(obs=33); id block set; by block set; run; * Aggregate, store the results back in count.; proc summary data=allocs nway missing; class set brand; output sum(count)=Count out=allocs(drop=_type_ _freq_); run; %mktkey(Brand1-Brand10) data key(keep=Brand Price); input Brand $ 1-8 Price $; datalines; Brand 1 Brand1 Brand 2 Brand2 Brand 3 Brand3 Brand 4 Brand4 Brand 5 Brand5 Brand 6 Brand6 Brand 7 Brand7 Brand 8 Brand8 Brand 9 Brand9 Brand 10 Brand10 . . ; %mktroll(design=sasuser.DrugAllo_LinDes, key=key, alt=brand, out=rolled, options=nowarn) proc print data=rolled(obs=11); format price dollar4.; run; proc sort data=rolled; by set brand; run; data allocs2; merge allocs(in=flag1) rolled(in=flag2); by set brand; if flag1 ne flag2 then put 'ERROR: Merge is not 1 to 1.'; format price dollar4.; run; proc print data=allocs2(obs=22); var brand price count; sum count; by notsorted set; id set; run; %mktallo(data=allocs2, out=allocs3, nalts=%eval(&nalts + 1), vars=set brand price, freq=Count) proc print data=allocs3(obs=22); var set brand price count c; run; proc transreg design data=allocs3 nozeroconstant norestoremissing; model class(brand price / zero=none) / lprefix=0; output out=coded(drop=_type_ _name_ intercept); id set c count; run; proc phreg data=coded; where count > 0; model c*c(2) = &_trgind / ties=breslow; freq count; strata set; run; data coded2; set coded; count = count / 10; run; proc phreg data=coded2; where count > 0; model c*c(2) = &_trgind / ties=breslow; freq count / notruncate; strata set; run; ****************** Begin Chair Example Code *****************; options ls=80 ps=60 nonumber nodate; title; title 'Generic Chair Attributes'; * This design will not be used; %mktex(3 ** 15, n=36, seed=238) %mktkey(3 5) %mktroll(design=randomized, key=key, out=cand) %mktruns(3 ** 5) %mktex(3 ** 5, n=243) %mktlab(data=design, int=f1-f3) proc print data=final(obs=27); run; %choiceff(data=final, model=class(x1-x5), nsets=6, maxiter=100, seed=121, flags=f1-f3, beta=zero) proc print; by set; id set; run; %mktex(3 ** 5, n=18) %mktlab(data=design, int=f1-f3) %choiceff(data=final, model=class(x1-x5), nsets=6, maxiter=20, seed=121, flags=f1-f3, beta=zero) proc print; run; %mktex(3 ** 5, n=27, seed=382) %mktlab(data=design, int=f1-f3) %choiceff(data=final, model=class(x1-x5), nsets=9, maxiter=20, seed=121, flags=f1-f3, beta=zero) proc print; id set; by set; var index prob x:; run; title 'Generic Chair Attributes'; %mktex(3 ** 5, n=243, seed=306) data final(drop=i); set design end=eof; retain f1-f3 1 f4 0; output; if eof then do; array x[9] x1-x5 f1-f4; do i = 1 to 9; x[i] = i le 5 or i eq 9; end; output; end; run; proc print data=final(where=(x1 eq x3 and x2 eq x4 and x3 eq x5 or f4)); run; %choiceff(data=final, model=class(x1-x5), nsets=6, maxiter=100, seed=121, flags=f1-f4, beta=zero) proc print; by set; id set; run; %mktex(3 ** 15, n=81 * 81, seed=522) %mktkey(3 5) data key; input (x1-x5) ($); datalines; x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15 . . . . . ; %mktroll(design=randomized, key=key, out=rolled) * Code the constant alternative; data final; set rolled; if _alt_ = '4' then do; x1 = 1; x2 = 1; x3 = 1; x4 = 1; x5 = 1; end; run; proc print; by set; id set; where set in (1, 100, 1000, 5000, 6561); run; %choiceff(data=final, model=class(x1-x5), nsets=6, nalts=4, maxiter=10, beta=zero, seed=109) ************ Begin Initial Designs Example Code *************; options ls=80 ps=60 nonumber nodate; title; * Force quitting at a particular point; * Overcomes nonportable stopping due to different machine speeds; %let mktexopts = maxiter=10 5 2, tabiter=5 10, maxtime=60 60 60; title 'Try to Improve an Existing Design'; %mktex(4 ** 25, n=80, seed=368) * Restore options; %let mktexopts = ; %mktex(4 ** 25, n=80, seed=306, init=design, maxtime=20) title 'Augment a Design'; %mktex(n=36, seed=292) data init; set randomized end = eof; f = 1; output; if eof then do; f = .; do i = 1 to 4; output; end; drop i; end; run; proc print; run; %mktex(2 ** 11 3 ** 12, n=40, init=init, fixed=f, seed=513, options=nosort) proc print; run; title 'Augment a Design'; %mktex(n=36, seed=292) %mktex(2 ** 11 3 ** 12, n=40, init=randomized, holdouts=4, seed=513, options=nosort) proc print data=design(firstobs=37); run; title 'Differential Design Initialization'; %mktex(4 ** 11, n=80) data init; set design; retain x12-x25 .; run; %mktex(4 ** 25, n=80, init=init, seed=472) %mkteval; data init(drop=j); set design; array x[25]; do j = 12 to 25; x[j] = -x[j]; end; run; %mktex(4 ** 25, n=80, init=init, seed=472, balance=1) %mkteval; ******* Begin Partial Profiles and Restrictions Code ********; options ls=80 ps=60 nonumber nodate; title; title 'Partial Profiles'; %mktex(3 ** 20, n=41, partial=5, seed=292, maxdesigns=1) %mktlab(values=. 1 2, nfill=99) data _null_; set final(firstobs=2); put (x1-x20) (2.); run; data des(drop=i); Set = _n_; set final(firstobs=2); array x[20]; output; do i = 1 to 20; if n(x[i]) then do; if x[i] = 1 then x[i] = 2; else x[i] = 1; end; end; output; run; %choiceff(data=des, model=class(x1-x20 / zero=none), nsets=40, nalts=2, beta=zero, init=des(keep=set), intiter=0) %choiceff(data=des, model=class(x1-x20 / zero=none), nsets=40, nalts=2, beta=zero, init=des(keep=set), intiter=0, drop=x12 x22 x32 x42 x52 x62 x72 x82 x92 x102 x112 x122 x132 x142 x152 x162 x172 x182 x192 x202) title 'Partial Profiles'; %mktex(4 ** 12, n=37, partial=4, seed=462, maxdesigns=1) %mktlab(values=. 1 2 3, nfill=99) proc print; run; title 'Partial Profiles'; %macro partprof; sum = 0; do k = 1 to 10; sum = sum + (x[k] = x[k+10] & x[k] = x[k+20]); end; bad = abs(sum - 4); %mend; %mktex(3 ** 30, n=198, optiter=0, tabiter=0, maxtime=0, order=random, out=sasuser.cand, restrictions=partprof, seed=382) %mktkey(3 10) %mktroll(design=sasuser.cand, key=key, out=rolled) %mktdups(generic, data=rolled, out=nodups, factors=x1-x10, nalts=3) proc print data=nodups(obs=9); id set; by set; run; %choiceff(data=nodups, model=class(x1-x10), seed=495, iter=10, nsets=27, nalts=3, options=nodups, beta=zero) proc print data=best; id set; by notsorted set; var x1-x10; run; %macro partprof; sum = 0; do k = 1 to 20; sum = sum + (x[k] = 1 & x[k+20] = 1 & x[k+40] = 1 & x[k+60] = 1 & x[k+80] = 1 & x[k+100] = 1); end; bad = abs(sum - 15); %mend; /* %mktex(2 ** 120, n=300, optiter=0, tabiter=0, maxtime=0, order=random, out=cand, restrictions=partprof, seed=424, maxstages=1, options=largedesign nosort resrep) */ %macro partprof; sum = 0; do k = 1 to 20; sum = sum + (x[k] = 1 & x[k+20] = 1 & x[k+40] = 1 & x[k+60] = 1 & x[k+80] = 1 & x[k+100] = 1); end; bad = abs(sum - 15); %mend; %macro partprof; sum = 0; do k = 1 to 20; sum = sum + (x[k] = 1 & x[k+20] = 1 & x[k+40] = 1 & x[k+60] = 1 & x[k+80] = 1 & x[k+100] = 1); end; bad = abs(sum - 15); if sum < 15 & x[j1] = 2 then do; k = mod(j1 - 1, 20) + 1; c = (x[k] = 1) + (x[k+20] = 1) + (x[k+40] = 1) + (x[k+60] = 1) + (x[k+80] = 1) + (x[k+100] = 1); if c >= 3 then bad = bad + (6 - c) / 6; end; %mend; %mktex(2 ** 120, n=300, optiter=0, tabiter=0, maxtime=0, order=random, out=cand, restrictions=partprof, seed=424, maxstages=1, options=largedesign nosort resrep) %mktkey(6 20) %mktroll(design=cand, key=key, out=rolled) proc print; by set; id set; var x:; where set le 5; run; %mktdups(generic, data=rolled, out=nodups, factors=x1-x20, nalts=6) proc print data=nodups(obs=18); id set; by set; run; %choiceff(data=nodups, model=class(x1-x20 / zero=first), seed=495, iter=10, nsets=18, nalts=6, options=nodups, beta=zero) proc print data=best; id set; by notsorted set; var x1-x20; run; /* %mktex(2 ** 120, n=400, optiter=0, tabiter=0, maxtime=60, order=random, out=cand, restrictions=partprof, seed=424, maxstages=1, options=largedesign nosort) */ %macro partprof; sum = 0; do k = 1 to 20; sum = sum + (x[k] = 1 & x[k+20] = 1 & x[k+40] = 1 & x[k+60] = 1 & x[k+80] = 1 & x[k+100] = 1); end; bad = abs(sum - 15); if sum < 15 & x[j1] = 2 then bad = bad + 1000; %mend; %mktex(2 ** 120, n=300, optiter=0, tabiter=0, maxtime=0, order=random, out=cand, restrictions=partprof, seed=424, maxstages=1, options=largedesign nosort resrep) %macro partprof; sum = 0; do k = 1 to 15; sum = sum + (x[k+15] = x[k] & x[k+30] = x[k] & x[k+45] = x[k] & x[k+60] = x[k]); end; bad = abs(sum - 10); if sum < 10 & x[j1] ^= x[mod(j1 - 1, 15) + 1] then bad = bad + 1000; %mend; %mktex(5 ** 75, n=400, optiter=0, tabiter=0, maxtime=0, order=random, out=cand, restrictions=partprof, seed=472, maxstages=1, options=largedesign nosort resrep) %mktkey(5 15) %mktroll(design=cand, key=key, out=rolled) %mktdups(generic, data=rolled, out=nodups, factors=x1-x15, nalts=5) %choiceff(data=nodups, model=class(x1-x15), seed=513, iter=10, nsets=15, nalts=5, options=nodups, beta=zero) proc print data=best(obs=15); id set; by notsorted set; var x1-x15; run; %choiceff(data=nodups, model=class(x1-x15), seed=513, iter=10, nsets=30, nalts=5, options=nodups, beta=zero) /* %macro partprof; sum = 0; do k = 1 to 15; sum = sum + (x[k+15] = x[k] & x[k+30] = x[k] & x[k+45] = x[k] & x[k+60] = x[k]); end; bad = abs(sum - 10); if sum < 10 then do; if x[j1] ^= x[mod(j1 - 1, 15) + 1] then bad = bad + 1000; if x[j2] ^= x[mod(j2 - 1, 15) + 1] then bad = bad + 1000; end; %mend; %mktex(5 ** 75, n=400, optiter=0, tabiter=0, maxtime=720, order=random=15, out=sasuser.cand, restrictions=partprof, seed=472, exchange=2, maxstages=1, options=largedesign nosort resrep) %mktkey(5 15) %mktroll(design=sasuser.cand, key=key, out=rolled) %mktdups(generic, data=rolled, out=nodups, factors=x1-x15, nalts=5) %choiceff(data=nodups, model=class(x1-x15), seed=513, iter=10, nsets=30, nalts=5, options=nodups, beta=zero) proc print data=best(obs=15); id set; by notsorted set; var x1-x15; run; */ proc iml; d = { 1 1 1 1 , 1 1 2 2 , 1 2 1 2 , 1 2 2 1 }; b = { 1 1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 4 5 6 7 , 2 5 8 11 14 5 6 7 10 5 6 7 9 5 6 7 8 9 10 8 , 3 6 9 12 15 8 12 9 13 13 8 10 11 10 9 11 12 12 11 13 , 4 7 10 13 16 11 14 15 16 15 16 12 14 14 13 16 15 16 15 14 }`; m = max(b); p = nrow(d); sets = nrow(b) # p; d2 = mod(d, 2) + 1; x = j(sets, 2 # m, 1); do i = 1 to nrow(b); j = ((i-1) # p : i # p - 1) + 1; x[j, b[i,] ] = d; x[j, b[i,] + m] = d2; end; x = (1:sets)` @ {1 1}` || shape(x, 2 # sets); m = ncol(x) - 1; vname = 'Set' || ('x1' : rowcatc('x' || char(m))); create design from x[colname=vname]; append from x; quit; proc print; by set; id set; var x:; where set le 8 or set ge 77; run; %mktex(2 4 2 2 2, n=8) proc print; run; data design; set design; drop x2; run; proc iml; b = { 1 1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 4 5 6 7 , 2 5 8 11 14 5 6 7 10 5 6 7 9 5 6 7 8 9 10 8 , 3 6 9 12 15 8 12 9 13 13 8 10 11 10 9 11 12 12 11 13 , 4 7 10 13 16 11 14 15 16 15 16 12 14 14 13 16 15 16 15 14 }`; create b from b; append from b; quit; %mktppro(ibd=b) %choiceff(data=chdes, model=class(x1-x16), nsets=80, nalts=2, beta=zero, init=chdes, initvars=x1-x16) %macro partprof; sum = 0; do k = 1 to 16; sum = sum + (x[k] = x[k+16]); end; bad = abs(sum - 12); %mend; %mktex(2 ** 32, n=1000, optiter=0, tabiter=0, order=random, out=sasuser.cand, restrictions=partprof, seed=382) %mktkey(2 16) %mktroll(design=sasuser.cand, key=key, out=rolled) %mktdups(generic, data=rolled, out=nodups, factors=x1-x16, nalts=2) %choiceff(data=nodups, model=class(x1-x16), seed=495, iter=20, nsets=80, nalts=2, options=nodups, beta=zero) proc print data=best; id set; by notsorted set; var x:; run; %choiceff(data=nodups, model=class(x1-x16), seed=495, iter=20, nsets=60, nalts=2, options=nodups, beta=zero) %choiceff(data=nodups, model=class(x1-x16), seed=495, iter=20, nsets=40, nalts=2, options=nodups, beta=zero) %choiceff(data=nodups, model=class(x1-x16), seed=495, iter=20, nsets=20, nalts=2, options=nodups, beta=zero) proc iml; b = { 1 1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 4 5 6 7 , 2 5 8 11 14 5 6 7 10 5 6 7 9 5 6 7 8 9 10 8 , 3 6 9 12 15 8 12 9 13 13 8 10 11 10 9 11 12 12 11 13 , 4 7 10 13 16 11 14 15 16 15 16 12 14 14 13 16 15 16 15 14 }`; m = max(b); p = nrow(b); q = ncol(b); f = j(m, m, 0); do i = 1 to p; do j = 1 to q; do k = j to q; f[b[i,j], b[i,k]] = f[b[i,j], b[i,k]] + 1; end; end; end; print f[format=1.]; x = j(p, m, 0); do i = 1 to p; x[i, b[i,]] = 1; end; print b[format=2.] ' ' x[format=1.]; quit; %macro res; bad = abs(sum(x = 2) - 4); %mend; %macro con; _f = ((1:&m) @ j(&m, 1, 1) > j(1, &m, 1) @ (1:&m)`) + 5 # i(&m); _p = (_f = 5) + 10 # (_f = 1); %mend; %macro res; bad = 1000 # abs(sum(x = 2) - 4); f = j(&m, &m, 0); do ii = 1 to &n; if ii = i then l = loc(x = 2); else l = loc(xmat[ii,] = 2); if ncol(l) then f[l, l] = f[l, l] + 1; end; bad = bad + sum(abs(f - _f ) # _p); %mend; %let n = 20; %let m = 16; proc iml; a = (1:&m); b = j(1, &m, 1); c = j(&m, 1, 1); d = (1:&m)`; e = (1:&m) @ j(&m, 1, 1); f = j(1, &m, 1) @ (1:&m)`; g = (1:&m) @ j(&m, 1, 1) > j(1, &m, 1) @ (1:&m)`; h = 5 # i(&m); _f = ((1:&m) @ j(&m, 1, 1) > j(1, &m, 1) @ (1:&m)`) + 5 # i(&m); print a[format=2.] b[format=2.]; print c[format=1.] ' ' d[format=2.] ' ' e[format=2.]; print f[format=2.] g[format=1.] h[format=1.] _f[format=1.]; quit; %mktex(2 ** 16, n=20, tabiter=0, optiter=0, restrictions=res, resmac=con, reslist=%str(_f, _p), order=random, options=resrep accept, exchange=2, seed=205, maxdesigns=1, out=sasuser.ibd2) proc print data=sasuser.ibd2; run; %mktex(2 4 2 2 2, n=8) data design; set design; drop x2; run; %mktppro(x=sasuser.ibd2) %choiceff(data=chdes, model=class(x1-x16), nsets=80, nalts=2, beta=zero, init=chdes, initvars=x1-x16) %mktex(2 4 2 2 2, n=8) data design; set design; drop x2; run; %mktppro(x=sasuser.ibd2) %choiceff(data=chdes, model=class(x1-x16), nsets=80, nalts=2, beta=zero, init=chdes, initvars=x1-x16) %macro con; _d = 3 # i(&m); _f = ((1:&m) @ j(&m, 1, 1) > j(1, &m, 1) @ (1:&m)`) + _d; _p = (_f = 3) + 10 # (_f = 1); %mend; %macro res; bad = 1000 # abs(sum(x = 2) - 4); f = j(&m, &m, 0); do ii = 1 to &n; if ii = i then l = loc(x = 2); else l = loc(xmat[ii,] = 2); if ncol(l) then f[l, l] = f[l, l] + 1; end; bad = bad + sum((abs(f - _f) >< abs(f - _d)) # _p); %mend; %mktex(2 ** 16, n=12, tabiter=0, optiter=0, restrictions=res, resmac=con, reslist=%str(_f, _p, _d), order=random, options=resrep nofinal, exchange=2, seed=151, maxdesigns=1, out=sasuser.ibd3, ridge=0.01) %mktex(2 4 2 2 2, n=8) data design; set design; drop x2; run; %mktppro(x=sasuser.ibd3) %choiceff(data=chdes, model=class(x1-x16), nsets=48, nalts=2, beta=zero, init=chdes, initvars=x1-x16) %macro con; _d = 2 # i(&m); _f = ((1:&m) @ j(&m, 1, 1) > j(1, &m, 1) @ (1:&m)`) + _d; _p = (_f = 2) + 10 # (_f = 1); %mend; %macro res; bad = 1000 # abs(sum(x = 2) - 4); f = j(&m, &m, 0); do ii = 1 to &n; if ii = i then l = loc(x = 2); else l = loc(xmat[ii,] = 2); if ncol(l) then f[l, l] = f[l, l] + 1; end; bad = bad + sum((abs(f - _f) >< abs(f - _d)) # _p); %mend; %mktex(2 ** 16, n=8, tabiter=0, optiter=0, restrictions=res, resmac=con, reslist=%str(_f, _p, _d), order=random, options=resrep nofinal, exchange=2, seed=17, maxdesigns=1, out=sasuser.ibd4, ridge=0.01) %mktex(2 4 2 2 2, n=8) data design; set design; drop x2; run; %mktppro(x=sasuser.ibd4) %choiceff(data=chdes, model=class(x1-x16), nsets=32, nalts=2, beta=zero, init=chdes, initvars=x1-x16) %macro con; _d = 2 # i(&m); _f = ((1:&m) @ j(&m, 1, 1) > j(1, &m, 1) @ (1:&m)`) + _d; _p = (_f = 2) + 10 # (_f = 1); %mend; %macro res; bad = 1000 # abs(sum(x = 2) - 6); f = j(&m, &m, 0); do ii = 1 to &n; if ii = i then l = loc(x = 2); else l = loc(xmat[ii,] = 2); if ncol(l) then f[l, l] = f[l, l] + 1; end; bad = bad + sum((abs(f - _f) >< abs(f - _d)) # _p); %mend; %mktex(2 ** 24, n=8, tabiter=0, optiter=0, restrictions=res, resmac=con, reslist=%str(_f, _p, _d), order=random, options=resrep nofinal, exchange=2, seed=114, maxdesigns=1, out=sasuser.ibd5, ridge=0.01) %mktex(3 6 3 ** 5, n=18) data design; set design; drop x2; run; proc print; run; %mktppro(x=sasuser.ibd5) %choiceff(data=chdes, model=class(x1-x24), nsets=48, nalts=3, beta=zero, init=chdes, initvars=x1-x24) proc print; by set; id set; var x:; where set le 6 or set gt 42; run; %macro con; _d = 2 # i(&m); _f = ((1:&m) @ j(&m, 1, 1) > j(1, &m, 1) @ (1:&m)`) + _d; _p = (_f = 2) + 10 # (_f = 1); %mend; %macro res; bad = 1000 # abs(sum(x = 2) - 4); f = j(&m, &m, 0); do ii = 1 to &n; if ii = i then l = loc(x = 2); else l = loc(xmat[ii,] = 2); if ncol(l) then f[l, l] = f[l, l] + 1; end; bad = bad + sum((abs(f - _f) >< abs(f - _d)) # _p); %mend; %mktex(2 ** 16, n=8, tabiter=0, optiter=0, restrictions=res, resmac=con, reslist=%str(_f, _p, _d), order=random, options=resrep nofinal, exchange=2, seed=114, maxdesigns=1, out=sasuser.ibd6, ridge=0.01) %mktex(4 ** 5, n=16) data design; set design; drop x2; run; %mktppro(x=sasuser.ibd6) %choiceff(data=chdes, model=class(x1-x16), nsets=32, nalts=4, beta=zero, init=chdes, initvars=x1-x16) proc print; by set; id set; var x:; where set le 6 or set gt 42; run; %macro con; _d = 2 # i(&m); _f = ((1:&m) @ j(&m, 1, 1) > j(1, &m, 1) @ (1:&m)`) + _d; _p = (_f = 2) + 10 # (_f = 1); %mend; %macro res; bad = 1000 # abs(sum(x = 2) - 4); f = j(&m, &m, 0); do ii = 1 to &n; if ii = i then l = loc(x = 2); else l = loc(xmat[ii,] = 2); if ncol(l) then f[l, l] = f[l, l] + 1; end; bad = bad + sum((abs(f - _f) >< abs(f - _d)) # _p); %mend; %mktex(2 ** 32, n=16, tabiter=0, optiter=0, restrictions=res, resmac=con, reslist=%str(_f, _p, _d), order=random, options=resrep nofinal, exchange=2, seed=420, maxdesigns=1, out=sasuser.ibd7, ridge=0.01) %mktex(4 ** 5, n=16) data design; set design; drop x2; run; %mktppro(x=sasuser.ibd7) %choiceff(data=chdes, model=class(x1-x32), nsets=64, nalts=4, beta=zero, init=chdes, initvars=x1-x32)