Multiple arrays with multiple lengths

Reply
Occasional Contributor
Posts: 6

Multiple arrays with multiple lengths

I am trying to use multiple arrays to count the number of times each of the conditions occur, but the number of variables in each array is different. I get the following error message when I run this code:

‘Array subscript out of range at line 173 column 4.’

Does anyone know a work around that will allow me to use multiple arrays with different lengths?

data femalea;

set femaleb;

Array Factor (*)  DX_FIB     DX_FII      DX_FV      DX_FVII      DX_FVIII      DX_FIX      DX_FX      DX_FXI      DX_FXIII      DX_PAI      DX_A2_ANTI ;

Array VWD (*) DX_VW_Type_1      DX_VW_Type_2A      DX_VW_Type_2B      DX_VW_Type_2M      DX_VW_Type_2N      DX_VW_Type_3      DX_VW_Type_UK;

Array Platelet (*)DX_PLATE_GT      DX_PLATE_BS      DX_PLATE_GPS      DX_PLATE_HPS      DX_PLATE_IT      DX_PLATE_Storage_Pool      DX_PLATE_Release_defect      DX_PLATE_Other;

Array Connective DX_CON_TIS_Ehlers_Danlos;

      Do f = 1 to 15;

                if factor(f) =1 and VWD (f)=1 then response =1;

                if factor (f) =1 and Platelet (f) =1 then response =1; if factor (f) =1 and Connective (f) =1 then response =1;

                 if VWD (f) =1 and Platelet (f) =1 then response =1;

                              end; run;

Super User
Posts: 17,750

Re: Multiple arrays with multiple lengths

Since your using the same index (f) for all arrays its hard to see a work around.

How are you expecting to compare factor array and platelet array if they don't have the same number?

Or factor and connective? Or VWD and Platelet?

I think you might be better off transposing and running a proc freq, but it depends on what you're looking for.

Occasional Contributor
Posts: 6

Re: Multiple arrays with multiple lengths

Thanks for your response – You are right this is actually just a step in the process of what I am trying to do. Honestly I am probably making it way more complicated that what it has to be. I am actually trying to create a variable that will count the number of times multiple types of diagnoses occur in one patient. For example a particular patient may have DX_FIB, DX_VW_Type_1, and DX_PLATE_GT. I am trying to create a new variable ‘response” that will count the overall number times multiple diagnoses occur in one patient.  Again thanks for your response.

PROC Star
Posts: 7,356

Re: Multiple arrays with multiple lengths

You have to explain more about what you are really trying to do.  Surely you're not trying to recompute the variable 'response' 45 times.

If that was just pseudo code and the question is simply how not to exceed an array's limits, you can always include extra statements like:

if f le dim(DX_VW_Type) then do;

for all array references where you con't want to exceed the number of entries in a particular array.

.

Occasional Contributor
Posts: 6

Re: Multiple arrays with multiple lengths

Thanks for your response – You are right this is actually just a step in the process of what I am trying to do. Honestly I am probably making it way more complicated that what it has to be. I am actually trying to create a variable that will count the number of times multiple types of diagnoses occur in one patient. For example a particular patient may have DX_FIB, DX_VW_Type_1, and DX_PLATE_GT. I am trying to create a new variable ‘response” that will count the overall number times multiple diagnoses occur in one patient.  Again thanks for your response.

Super User
Super User
Posts: 6,497

Re: Multiple arrays with multiple lengths

Are the variables in your arrays boolean (1/0) values?

If so you sum them to get the number of responses (assuming 1 means response).

data femalea;

  set femaleb end=eof;

  array Factor(*) DX_FIB DX_FII DX_FV DX_FVII DX_FVIII DX_FIX DX_FX DX_FXI DX_FXIII DX_PAI DX_A2_ANTI ;

  array VWD (*) DX_VW_Type_1 DX_VW_Type_2A DX_VW_Type_2B DX_VW_Type_2M DX_VW_Type_2N DX_VW_Type_3 DX_VW_Type_UK;

  array Platelet (*) DX_PLATE_GT DX_PLATE_BS DX_PLATE_GPS DX_PLATE_HPS DX_PLATE_IT DX_PLATE_Storage_Pool DX_PLATE_Release_defect DX_PLATE_Other;

  array Connective (*) DX_CON_TIS_Ehlers_Danlos;

  ndx = sum(of 0 factor(*) vwd(*) platelet(*) connective(*) );

  response = ndx > 1 ;

  total_subjects + response ;

  if eof then put 'Total number of subjects with more than one DX = ' total_subjects ;

run;

Note if you just want to sum up the variables that start with DX_ then you can skip the array statements.

ndx = sum(of DX_: ) ;

Occasional Contributor
Posts: 10

Re: Multiple arrays with multiple lengths

SEE IF THIS HELPS...


counter = 0;

*COMPARISON OF ARRAY1 WITH ARRAY2;

i= DIM(ARRAY1);

j= DIM(ARRAY2);

do x= 1 to i;

     do y= 1 to j;

           Counter + (ARRAY1(x)=1 and ARRAY2(y)=1);

     end;

end;

run;


REPEAT THE ABOVE STEPS FOR THE OTHER ARRAY COMPARISONS... KEEP THE COUNTER RUNNING WITHOUT RESETTING AND YOU SHOULD HAVE YOUR RESULT

Ask a Question
Discussion stats
  • 6 replies
  • 237 views
  • 0 likes
  • 5 in conversation