BookmarkSubscribeRSS Feed
branbran
Calcite | Level 5

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;

6 REPLIES 6
Reeza
Super User

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.

branbran
Calcite | Level 5

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.

art297
Opal | Level 21

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.

.

branbran
Calcite | Level 5

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.

Tom
Super User Tom
Super User

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_: ) ;

Apprentice
Calcite | Level 5

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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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
  • 6 replies
  • 756 views
  • 0 likes
  • 5 in conversation