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

Greetings,

 

I am trying to combine two sets of 233 variables into one in a data set. (I have data from two identical measures, each with 233 variables, that were recorded as separate columns based on whether the participant was contacted via text or email.) The variables have the prefix cbe_ or cbt_ based on which measure was used. So, for instance, I would ultimately like to have a third variable, cba_firstvar, that has values equal to those of cbe_firstvar for the cases who were contacted via e-mail and values equal to those of cbt_ firstvar for the cases who were contacted via text. 

 

As a first step, I have been attempting to create the cba_ variables based on the cbt_ variables using an array. This is the code I have:

 

array textn {*}

cbt_firstvar

cbt_secondvar

cbt_thirdvar;

array combinedn {*}

cba_firstvar

cba_secondvar

cba_thirdvar;

do k=1 - dim(textn);

combinedn{k} = textn{k};

end;

 

When I run it, I receive this error message: 

 

ERROR: Array subscript out of range at line 18763 column 16.

 

I cannot figure out why I am receiving this message since I believe the "dim(textn)" code is requesting SAS to define the upper bound of k. 

 

I'm also unsure if this is the best strategy to achieve my ultimate goal. The data were collected in REDCap, so I can use the export function to separate it into two sets -- one with cases who were contacted via text and the other via e-mail. My current plan is to create the third variables with the cba_ prefix in each of the two separate data sets and then combine them.

 

(Also, I'm running SAS v9.4.)

 

Any help would be greatly appreciated. Thanks for your time and consideration!

 

 

Andrew

1 ACCEPTED SOLUTION
7 REPLIES 7
abarnett313
Calcite | Level 5

Thank you so much! I am new to using arrays. Can't believe it was such an obvious mistake. 

Kurt_Bremser
Super User

The details:

A data step do allows the use of until() and while() conditions, increments/decrements (where you supply a termination value with "to", and the increment/decrement steps with "by"), and/or value lists. Your syntax ended up being a value list with a single value, which is syntactically valid during compilation, but caused a runtime error when the resulting value was used as an array index.

abarnett313
Calcite | Level 5

That makes sense. Thanks again! It worked when I made that correction.

abarnett313
Calcite | Level 5

This code works, but I noticed that it also creates a variable in the dataset named k (equivalent to the number of items in the array +1 for all rows of data). Is this to be expected? 

abarnett313
Calcite | Level 5

Thanks. I just wanted to be sure the creation of the variable didn't indicate that I had a problem in my code!

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
  • 7 replies
  • 710 views
  • 0 likes
  • 2 in conversation