BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
calmac
Fluorite | Level 6

Hi all,
I've designed an experiment using SAS macros and now I have collected a small pre-test sample to analyse the results and check if something is wrong before collecting all my data (N=1000). The design should be correct but now I'm trying to figure out how to merge/analyse the data. 
I describe step by step what I've done so far, it is rather long and perhaps tedious for the experts, but my belief is that looking at the whole process could be very helpful for those (like me) who have just started learning SAS applied to discrete choice modelling.
The experiment consists of a series of binary choices in order to indirectly determine participants' willingness to pay for specific features of an online service. The proposed choices are between two general options A vs B. I have 14 features, of which 13 are binary (i.e., 1=feature shown, 0=feature not shown) and 1 feature has 8 levels (i.e., price, 1-2-3-4-5-6-7-8 dollars). So, my design is asymmetric, fractional factorial, and uses blocks.
The design is created as follows:

%mktruns (2 ** 13 8) /* tells me that a design size of 64 is a 100% efficient design*/

%mktex(2**13 8, n=64, seed=205) /* gives me an efficient solution (i.e., 100) */

*/ After this I label variables and create the two options: */

proc format;
value Status_update 1 = 1 2 = 0;
value Notes 1 = 1 2 = 0;
value Comments 1 = 1 2 = 0;
value Wall_posts 1 = 1 2 = 0;
value Private_messages 1 = 1 2 = 0;
value Chats 1 = 1 2 = 0;
value Groups 1 = 1 2 = 0;
value Newsfeed 1 = 1 2 = 0;
value Like 1 = 1 2 = 0;
value Photos_videos 1 = 1 2 = 0;
value Events 1 = 1 2 = 0;
value Gaming 1 = 1 2 = 0;
value Fan_pages 1 = 1 2 = 0;
value Price 1 = $0 2 = $1 3 = $2 4 = $3 5 = $4 6 = $5 7 = $6 8 = $7;
run;

%mktlab(data=design, /* input data set */
vars=Status_update Notes Comments Wall_posts Private_messages Chats Groups Newsfeed Like Photos_videos Events Gaming Fan_pages Price, /* new attribute names */
int=f1-f2, /* create 2 columns of 1’s in f1-f2 */
out=final, /* output design add a format statement for the attributes */
stmts=format Status_update Status_update. Notes Notes. Comments Comments. Wall_posts Wall_posts. Private_messages Private_messages. Chats Chats. Groups Groups. Newsfeed Newsfeed. Like Like. Photos_videos Photos_videos. Events Events. Gaming Gaming. Fan_pages Fan_pages. Price Price.)
proc print; run;

and now I run %choiceff (thanks to Mr Kuhfeld):

%choiceff(data=final, /* candidate set of alternatives */
bestout=sasuser.facebookdes, /* choice design permanently stored */
/* model with stdz orthog coding */
model=class(Status_update Notes Comments Wall_posts Private_messages Chats Groups Newsfeed Like Photos_videos Events Gaming Fan_pages Price / sta),
nsets=64, /* number of choice sets to make */
seed=205, /* random number seed */
flags=f1-f2, /* flag which alt can go where, 2 alts*/
options=relative, /* display relative D-efficiency */
beta=zero) /* assumed beta beta vector */

as there are 64 choice sets, it appeared advisable to create blocks, specifically 4 blocks with 8 choice sets each:

%mktblock(data=final, /* input choice design to block */
out=sasuser.facebookdes, /* output blocked choice design stored in permanent SAS data set */
nalts=2, /* two alternatives */
nblocks=4, /* four blocks */
factors=Status_update Notes Comments Wall_posts Private_messages Chats Groups Newsfeed Like Photos_videos Events Gaming Fan_pages Price, /* 14 attributes, x1-x14 */
print=design, /* print the blocked design (only) */
seed=205) /* random number seed */

At this point a small pretest has been run, N=51, where each participant has been shown 1 random block (8 choice sets). I have read the data as follows:

data chdata;
input Block Sub (c1-c8) (1.) @@;
datalines;
4 1 12212111
3 2 21121121
1 3 12212112
4 4 12211221
2 5 12211221
2 6 21121221
4 7 11111111
2 8 21121221
3 9 21121121
1 10 12212112
2 11 21221221
1 12 12211221
3 13 21122112
2 14 12211221
3 15 22111121
2 16 12221212
2 17 21121221
4 18 12211221
4 19 12212111
2 20 11111111
4 21 12212111
2 22 21121221
3 23 12211121
3 24 21122111
3 25 12211121
4 26 22221111
1 27 21111112
4 28 12211121
2 29 11221221
2 30 12121221
3 31 21121121
4 32 12211121
2 33 11211221
1 34 12211221
1 35 12212112
1 36 11112222
1 37 12211221
1 38 12211121
4 39 12212112
3 40 21121121
1 41 12212222
4 42 12212111
1 43 12211222
2 44 12211221
1 45 11111221
4 46 12212112
4 47 12212112
3 48 12211111
4 49 12212111
1 50 11212112
4 51 12212111
;

At this point the idea was to merge data and design and analyse data as follows: 

%mktmerge(design=sasuser.facebookdes, /* input final blocked choice design */
data=chdata, /* input choice data */
out=desdata, /* output design and data */
blocks=block, /* the blocking variable is block */
nsets=8, /* 8 choice sets per subject */
nalts=2, /* 2 alternatives in each set */
setvars=c1-c8) /* the choices for each subject vars */

%phchoice(on) /* customize PHREG for a choice model */

proc phreg brief data=desdata; /* provide brief summary of strata */
ods output parameterestimates=pe; /* output parameter estimates */
class x1-x14 / ref=first; /* name all as class vars, ’1’ ref level*/
model c*c(2) = x1-x14 ; /* 1 - chosen, 2 - not chosen */
/* x1-x14 are independent vars */
strata block sub set; /* set within subject within block */
run; /* identify each choice set */

However, the proc phreg generates an error after the class command (i.e., ERROR: Variable X1 not found).

MY QUESTION: I can't understand what I'm doing wrong and whether this error is related to the way I block the design or how I manage the merge. Any help would be greatly appreciated.

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisNZ
Tourmaline | Level 20

The variables in the class statement should not be listed inside parentheses.

 

If you look at the log ( I can't do that since you did not post the whole log) , you'll probably see that the opening parenthesis is underlined to show where the error is.

 

View solution in original post

6 REPLIES 6
ChrisNZ
Tourmaline | Level 20

I don't see a variable X1 anywhere in your code. Is that expected?

calmac
Fluorite | Level 6

No it's not. My apologies @, I posted the code I used before labeling the variables.
The code I actually use is:

proc phreg brief data=desdata; /* provide brief summary of strata */
ods output parameterestimates=pe; /* output parameter estimates */
class (Status_update Notes Comments Wall_posts Private_messages Chats Groups Newsfeed Like Photos_videos Events Gaming Fan_pages Price) / ref=first; /* name all as class vars, ’1’ ref level*/
model c*c(2) = (Status_update Notes Comments Wall_posts Private_messages Chats Groups Newsfeed Like Photos_videos Events Gaming Fan_pages Price); /* 1 - chosen, 2 - not chosen */
/* these are independent vars */
strata block sub set; /* set within subject within block */
run; /* identify each choice set */

and the error I get at the line "class (Status_update Notes Comments ... " is the following:

 

ERROR 22-322: Syntax error, expecting one of the following: a name, ;, /, _ALL_, _CHARACTER_, _CHAR_, _NUMERIC_.
ERROR 79-322: Expecting a (.
ERROR 200-322: The symbol is not recognized and will be ignored.

 

sorry for posting the wrong code.

ChrisNZ
Tourmaline | Level 20

The variables in the class statement should not be listed inside parentheses.

 

If you look at the log ( I can't do that since you did not post the whole log) , you'll probably see that the opening parenthesis is underlined to show where the error is.

 

calmac
Fluorite | Level 6

Thank you very much @ChrisNZ, I deleted parentheses from class and from model statement and the error is gone.

 

One last question, if you don't mind, about blocking and %mktmerge macro. Technically speaking the subjects of an experiment should each see exactly one choice set (also Kuhfeld mention this in his book about SAS macros). I'm showing to each participant one block only out of the four in my design, randomly chosen (i.e. this means that each person takes 8 choice sets) cause I think this is the purpose of blocking. Is this the way to go, or should I show them 1 choice set from each block?

ChrisNZ
Tourmaline | Level 20

Sorry, I can't help you there. I have never used these macros nor proc phreg, and never made such designs. 🙂

Try asking the question in the Analytics forum?

calmac
Fluorite | Level 6

No problem, thanks anyway for helping me out, you made my day. Cheers

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

How to Concatenate Values

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

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 1579 views
  • 2 likes
  • 2 in conversation