CharlieATX
CharlieATX

Reputation: 13

Identifying CharacterStrings with Arrays and Index Function SAS

I have several (55 to be exact) variables in my dataset that are large blocks of text. These variables hold the results of certain medical procedures.

I am trying to use the index function in combination with an array in SAS to identify observation where certain key words are present in one or more of the 55 results variables. For example, where the word "REPAIR" is present.

data c1;
set c; 

  array res  results1-results55; 

  array outres _numeric_; 

      do i= 1 to dim(outres);

      outres(i) = index(res(i), "REPAIR");

      end; 

  run; 

I can get my code to work when only one variable is being indexed; however, it breaks when trying to use an array to look across all 55 results variables for the word "REPAIR". I get the following error:

         ERROR: Array subscript out of range at line 1338 column 19.

Any thoughts on how to debug this?

THANKS!

Upvotes: 1

Views: 211

Answers (2)

Tom
Tom

Reputation: 51566

You asked SAS to make the array OUTRES from all of your existing numeric variables. The number of those probably does not match the 55 variables you assigned to the RES array.

If you want SAS to create NEW variables then you most either list them or at least tell SAS how many there should be. Here are some examples that should work.

array outres outres1-outres55 ;
array outres(55) ;

Upvotes: 1

D. O.
D. O.

Reputation: 626

Try to change

 array outres _numeric_; 

to

array outres[*] _numeric_; 

Upvotes: 0

Related Questions