BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
robertrao
Quartz | Level 8

  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

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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;

View solution in original post

5 REPLIES 5
Tom
Super User Tom
Super User

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;

robertrao
Quartz | Level 8

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

Tom
Super User Tom
Super User

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.

robertrao
Quartz | Level 8

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

Linlin
Lapis Lazuli | Level 10

try

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

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 5 replies
  • 877 views
  • 3 likes
  • 3 in conversation