Using substr function in arrays

Reply
N/A
Posts: 0

Using substr function in arrays

Hi

I am new to SAS, so please bear with me. I am trying to use an array to split a 240 character field of death codes into 48 new variables, each with a width of 5 characters .... with a starting position that moves from 1, 6, 11, 16, 21 etc. Alas, my syntax below keeps succumbing to the error message "The array subscript is out of range":

data b;
set a;
array split(48) $ entity1 - entity48;
do i = 1-48;
j = ((i-1)*5)+1;
split(i) = substr(entity_axis_data,j,5);
end;
run;

Any pearls of wisdom would be appreciated immensely.

Janine
Frequent Contributor
Posts: 91

Re: Using substr function in arrays

Try this:

data b;
set a;
length entity1 - entity48 $5;
array split(48) entity1 - entity48;
do i = 1 to 48;
j = ((i-1)*5)+1;
split(i) = substr(entity_axis_data,j,5);
end;
run;
N/A
Posts: 0

Re: Using substr function in arrays

Ripper! It worked a treat. Many thanks Advoss.
Ask a Question
Discussion stats
  • 2 replies
  • 364 views
  • 0 likes
  • 2 in conversation