turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- General Programming
- /
- Multiple arrays with multiple lengths

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

03-08-2013 04:36 PM

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;

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

03-08-2013 04:48 PM

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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

03-08-2013 05:09 PM

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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

03-08-2013 04:56 PM

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.

.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

03-08-2013 05:11 PM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

03-08-2013 08:23 PM

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

03-09-2013 07:36 PM

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