BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jws47
Calcite | Level 5
Hi All - I am trying to build a Discrete Choice Experiment (DCE) questionnaire in SAS. I am trying to build a DCE with four generic attributes at three levels, presented in 18 runs. 
In each run, respondents will be presented with two alternatives, plus a constant alternative (declining both alternatives).
I am using the following code, but I am generating the error ERROR: Too few variables defined for the dimension(s) specified for the array x.

title 'Generic Distribution Attributes'; %mktex (3 ** 4, n=18, seed=17); data final (drop=i); set design end=eof; retain f1-f2 1 f3 0; output; if eof then do; array x[18]x1-x4 f1-f3; do i=1 to 18; x[i] = i le 4 or i eq 18; end; output; end; run; proc print data=final(where=(x1 eq x3 and x2 eq x4 or f3)); run;


How can I fix this?
1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
array x[18]x1-x4 f1-f3;

Your array statement lists 18 items and you loop over 18 items. But X1-X4 is 4 and F1-F3 is 3, which means you're only providing 7 variables for an array you've declared as size 18. You need 11 more variables. 

 

Without having further information about your input data structure, I'm not sure how to fix this.

 

FYI - the code blocks are for code, your text should go outside the code blocks for legibility. One of the benefits of a code block is to be able to copy just that and paste it into an editor without changes. If you have it all together it doesn't provide that benefit. 


@jws47 wrote:
Hi All - I am trying to build a Discrete Choice Experiment (DCE) questionnaire in SAS. I am trying to build a DCE with four generic attributes at three levels, presented in 18 runs. 
In each run, respondents will be presented with two alternatives, plus a constant alternative (declining both alternatives).
I am using the following code, but I am generating the error ERROR: Too few variables defined for the dimension(s) specified for the array x.

title 'Generic Distribution Attributes'; %mktex (3 ** 4, n=18, seed=17); data final (drop=i); set design end=eof; retain f1-f2 1 f3 0; output; if eof then do; array x[18]x1-x4 f1-f3; do i=1 to 18; x[i] = i le 4 or i eq 18; end; output; end; run; proc print data=final(where=(x1 eq x3 and x2 eq x4 or f3)); run;


How can I fix this?



View solution in original post

2 REPLIES 2
Reeza
Super User
array x[18]x1-x4 f1-f3;

Your array statement lists 18 items and you loop over 18 items. But X1-X4 is 4 and F1-F3 is 3, which means you're only providing 7 variables for an array you've declared as size 18. You need 11 more variables. 

 

Without having further information about your input data structure, I'm not sure how to fix this.

 

FYI - the code blocks are for code, your text should go outside the code blocks for legibility. One of the benefits of a code block is to be able to copy just that and paste it into an editor without changes. If you have it all together it doesn't provide that benefit. 


@jws47 wrote:
Hi All - I am trying to build a Discrete Choice Experiment (DCE) questionnaire in SAS. I am trying to build a DCE with four generic attributes at three levels, presented in 18 runs. 
In each run, respondents will be presented with two alternatives, plus a constant alternative (declining both alternatives).
I am using the following code, but I am generating the error ERROR: Too few variables defined for the dimension(s) specified for the array x.

title 'Generic Distribution Attributes'; %mktex (3 ** 4, n=18, seed=17); data final (drop=i); set design end=eof; retain f1-f2 1 f3 0; output; if eof then do; array x[18]x1-x4 f1-f3; do i=1 to 18; x[i] = i le 4 or i eq 18; end; output; end; run; proc print data=final(where=(x1 eq x3 and x2 eq x4 or f3)); run;


How can I fix this?



jws47
Calcite | Level 5

Reeza - Thank you for your response! I changed the magnitude of the array and it worked. Thank you!

 

Julia

 

Ps. Thank you for your notes on posting etiquette - very helpful!

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

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

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

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

View all other training opportunities.

Discussion stats
  • 2 replies
  • 4013 views
  • 2 likes
  • 2 in conversation