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
- /
- Selecting consecutive elements from an array

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

08-22-2014 12:11 PM

I am trying to find a way to select consecutive elements in an array for comparison using the least amount of code as possible. For example, I have two arrays, Dx and ICD, and I want to compare each element of Dx to a group of elements in ICD... I'm checking to see if a particular diagnosis code belongs to a certain family of codes.

Ex.

data test.test;

set test.dx;

retain cat1 cat2 cat3....... cat49;

ARRAY DX(4) DX1 DX2 DX3 DX4;

ARRAY ICD(49) $7. c1 - c49('code1', 'code2', 'code3',.... ....., 'code49');

do I= 1 to dim(DX);

if DX(I) = ICD(1) then cat1='first family';

else if DZ(I) =ICD(2) then cat1='second family;

/* what if I wanted to compare a single value from the first array to a group of consecutive values in the second array

say... else if **DX(I) = ICD(3) - ICD(20)** then cat3='third family'; * I know this is syntactically incorrect

If I didn't want to do a **DX(I) =ICD(3) DX(I) =ICD(4)...... ..... DX(I)=ICD(20)** comparison for each element separately,

how can I do this in one step?

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

Posted in reply to mjk1961

08-22-2014 12:45 PM

I think you need to provide some example input data and expected output.

It also may be worth considering a custom format or two for your ICD codes.

If you aren't really married to "first" "second" etc

Also I'm not sure if your example code in the else is what you intended as you have Cat1='second family' but then

do I=1 to dim(dx);

if DX(I) = ICD(1) then cat1='first family';

else if DX(I) =ICD(2) then cat1='second family;

else do j=3 to 20;

if dx(I) = ICD(j) then cat3 = 'third family';

end;

end;

and since you have cat1-cat49 and c1-c49 I suspect there's more going on than you may have stated, which is why example input and output data may be needed.

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

Posted in reply to mjk1961

08-22-2014 01:07 PM

Not sure about the logic behind this looping. How about if dx1=icd5 but not equal to icd6 what will be the value of cat3 then?

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

Posted in reply to mjk1961

08-22-2014 01:12 PM

I might consider making some arrays of the families and then using them with IN array-name operator. Also what @stat@sas said that loop logic looks fishy.

set test.dx;

retain cat1 cat2 cat3.

ARRAY DX(

array fam3

do I=

if DX(I) eq ICD(

else if DX(I) eq ICD(

else if DX(I) in fam3 then cat3='third family';