## Array Question

Solved
Super Contributor
Posts: 1,041

# Array Question

I want to scan from D1 thru D7 and check if a person has 550

After checking that i also want to check if a particular code say (204) occurs after 550 or Prior to 550!!!!

D1    D2    D3      D4         D5        D6       D7
315   316   317   550      509      612     204

204    550   312    101     990      317      880

Thanks

Accepted Solutions
Solution
‎06-13-2013 11:01 AM
Super User
Posts: 8,127

## Re: Array Question

Use WHICHN function.

data have;

input d1-d7;

f550 = whichn(550, of d1-d7);

f204 = whichn(204, of d1-d7);

before = (0 < f204 < f550);

put (_all_) (=);

cards;

315 316 317 550 509 612 204

204 550 312 101 990 317 880

run;

All Replies
Solution
‎06-13-2013 11:01 AM
Super User
Posts: 8,127

## Re: Array Question

Use WHICHN function.

data have;

input d1-d7;

f550 = whichn(550, of d1-d7);

f204 = whichn(204, of d1-d7);

before = (0 < f204 < f550);

put (_all_) (=);

cards;

315 316 317 550 509 612 204

204 550 312 101 990 317 880

run;

Super Contributor
Posts: 1,041

## Re: Array Question

Hi ,

Could you explain me what is happening in this step???

before = (0 < f204 < f550);

how are we getting before =0 and before=1???

d1=315 d2=316 d3=317 d4=550 d5=509 d6=612 d7=204 f550=4 f204=7 before=0

d1=204 d2=550 d3=312 d4=101 d5=990 d6=317 d7=880 f550=2 f204=1 before=1

Thanks

Super User
Posts: 8,127

## Re: Array Question

When SAS evaluates logic expressions it generates 0 for FALSE and 1 for TRUE.

So when the index for 204 is found (F204 > 0) and before the index for 550 (F204 < F550) then the expression is TRUE so the variable is set to 1.

Super Contributor
Posts: 1,041

## Re: Array Question

Hi,

I was wondering if WHICHN works on missing values??

list1  list2   list3

3            32

missing=whichn(. , list1-list3)

we would not get 2 in this case if i am not wrong!!!!!

Thanks

Super Contributor
Posts: 1,636

## Re: Array Question

try

missing=whichc(.,of list1-list3);

🔒 This topic is solved and locked.