Help using Base SAS procedures

Array Code

Accepted Solution Solved
Reply
Super Contributor
Posts: 1,040
Accepted Solution

Array Code


Hi,

I also want to include a condition that if any of the these codes are not present then Arrhythemia='None';

I tried to use NOT IN condition and i dont get it right??

Could you help resolve.

Thanks


Accepted Solutions
Solution
‎05-13-2013 03:58 PM
Super User
Posts: 17,865

Re: Array Code

You need to look up if/else if/else operations.

data diag_array;

set daig_cohort;

array diag(50) dx1-dx50;

do i=1 to 35;

if diag(i) EQ '427.31' THEN Arrhythemia='flu1';

else if diag(i) EQ '427.32' THEN Arrhythemia='flu2';

else if diag(i) in('427','427.0','427.2','427.3','427.60', '427.61', '427.8', '427.81', '427.89', '427.9') THEN Arrhythemia='Other';

else Arrhythemia='None';

end;

run;

View solution in original post


All Replies
Solution
‎05-13-2013 03:58 PM
Super User
Posts: 17,865

Re: Array Code

You need to look up if/else if/else operations.

data diag_array;

set daig_cohort;

array diag(50) dx1-dx50;

do i=1 to 35;

if diag(i) EQ '427.31' THEN Arrhythemia='flu1';

else if diag(i) EQ '427.32' THEN Arrhythemia='flu2';

else if diag(i) in('427','427.0','427.2','427.3','427.60', '427.61', '427.8', '427.81', '427.89', '427.9') THEN Arrhythemia='Other';

else Arrhythemia='None';

end;

run;

Super User
Posts: 5,085

Re: Array Code

As Reeza indicated, you would do well to learn the ELSE statement.  But your problem lies in another area.

You only have 1 variable you are setting, but you examine 35 diagnosis codes.  What should happen if dx1='427.31' and dx2='427.32' and dx3='555'?  That's not a programming issue, that's a matter of thinking through the result you would like to achieve.

Each time through your DO loop, you overwrite the value of your new variable.  So in your code, dx35 is the only one that matters.  Its value is the only one determining your new variable.

Good luck.

Occasional Contributor
Posts: 15

Re: Array Code

Responding to your original code, looks like you would like to parse across 50 columns(diag) and thru 1000 rosw to set condition for Arrhythemia.

Heres my quick solution. Giv it a shot -


data diag_array;
  set daig_cohort;

  eligdiag = 0;
  array diag(50) dx1-dx50;

  do i=1 to 50;
IF diag(i) EQ '427.31' THEN DO;
  eligdiag = 1;
     Arrhythemia='flu1';
END;

ELSE IF diag EQ '427.32' THEN Arrhythemia='flu2' THEN DO;
  eligdiag = 1;
  Arrhythemia='flu2';
END;

ELSE IF diag in('427','427.0','427.2','427.3','427.60', '427.61', '427.8', '427.81', '427.89', '427.9') THEN DO;
  eligdiag = 1;
  Arrhythemia='Other';
END;

    ELSE DO;
  eligdiag = 0;
  Arrhythemia='None';
END;

    IF eligdiag = 1 then leave;
  end;

  DROP eligdiag;
run;

the LEAVE statement is the key here.

Gud Luk!

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 259 views
  • 3 likes
  • 4 in conversation