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


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

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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

3 REPLIES 3
Reeza
Super User

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;

Astounding
PROC Star

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.

sascom10
Calcite | Level 5

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!

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 3 replies
  • 917 views
  • 3 likes
  • 4 in conversation