ERROR: Array subscript out of range at line 65 column 13.

Reply
Frequent Contributor
Posts: 130

ERROR: Array subscript out of range at line 65 column 13.

In the sample data attached, there are 44 variables: A_1 - A_22, and  B_1 - B_22.

I try to create two new variables: A_DUMMY and B_DUMMY, such that A_DUMMY will contain A_1 to A_22, and B_DUMMY will contain B_1 to B_22.

The following 'code 1' works well for creating B_DUMMY, but it doesn't work for A_DUMMY (since A_1, A_2, A_3, A_4, and A_9 originally contain no value). The error message from creating A_DUMMY is "ERROR: Array subscript out of range at line 65 column 13."

*code 1;

DATA array_error_sample;

SET try.array_error_sample;

ARRAY B B_1-B_22;

I = 0;

DO WHILE (B_DUMMY = .);

  I = I+1;

  B_DUMMY = B{I};

END;

DROP I;

RUN;

DATA array_error_sample;

SET array_error_sample;

ARRAY A A_1-A_22;

I = 0;

DO WHILE (A_DUMMY = .);

  I = I+1;

  A_DUMMY = A{I};

END;

DROP I;

RUN;

The following 'code 2' creates A_DUMMY and B_DUMMY with only one value in each, no error message in log.

*code 2;

data array_error_sample;

set try.array_error_sample;

array B{22} B_1-B_22;

  i=0;

  do until (i>21);

  i+1;

  B_DUMMY=B{i};

  end;

  drop i;

run;

data array_error_sample;

set array_error_sample;

array A{22} A_1-A_22;

  i=0;

  do until (i>21);

  i+1;

  A_DUMMY=A{i};

  end;

  drop i;

run;

Attachment
Super Contributor
Posts: 336

Re: ERROR: Array subscript out of range at line 65 column 13.

Try:

Data array_error_sample;

  Set try.array_error_sample;

  Array B B_1-B_22;

  Array A A_1-A_22;

  B_Dummy=Sum(of B_1-B_22);

  A_Dummy=Sum(of A_1-A_22);

Run;

Frequent Contributor
Posts: 130

Re: ERROR: Array subscript out of range at line 65 column 13.

Thanks! that works well when each variable have only one value,but that may not always the case. (my sample data set is simplified for easy demonstration)

Grand Advisor
Posts: 10,196

Re: ERROR: Array subscript out of range at line 65 column 13.

What does "such that A_DUMMY will contain A_1 - A_22," mean? Do you want A_Dummy to have A_1 minus A_22, to have a string with the value "A_1 - A_22" or to have the values of all of the variables from A_1 to A_22. If this last idea then the only way will be to concatenate string values as a SAS numeric value can only contain one value.

Possibly you want

B_dummy = cats(of B_1-B_22);

Frequent Contributor
Posts: 130

Re: ERROR: Array subscript out of range at line 65 column 13.

the result of the following is close to what I want

B_Dummy=cats(of B_1-B_22);

A_Dummy=cats(of A_1-A_22);

the result of above is character. I try to use input function to convert then to numeric,but input(B_Dummy, 12.10) or  input(A_Dummy, 12.10) doesn't work.RESULT.png

Ask a Question
Discussion stats
  • 4 replies
  • 663 views
  • 6 likes
  • 3 in conversation