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

I have a list of diagnosis codes, and I want to flag if any of those codes exist anywhere in 15 different diagnosis variables. I created a series of IF-THEN statements, but I have many such lists of DX codes and an array is a more efficient approach. However, the array is only flagging a very small percentage of cases that should be flagged (I confirmed this by manually searching the data file). The cases that it does flag hit on various DX variables (DX1, DX3, DX12, etc), so it's not like the array is only searching DX15 or something like that.

 

%let PTB_all_list = ("O6010X","O6012X","Z3A22","Z3A23","Z3A24","Z3A25","Z3A26","Z3A27","O6013X",
					 "O6014X","Z3A28","Z3A29","Z3A30","Z3A31","Z3A32","Z3A33","Z3A34","Z3A35",
					 "Z3A36");
					 
DATA want; SET have;

ARRAY dx_codes DX1-DX15;
  do index=1 to dim(dx_codes ); 
IF dx_codes[index] in: (&PTB_all_list.) THEN PTB_birth_array=1; ELSE PTB_birth_array=0;
end;

IF (DX1 in (&PTB_all_list.) OR 
	DX2 in (&PTB_all_list.) OR
	DX3 in (&PTB_all_list.) OR
	DX4 in (&PTB_all_list.) OR
	DX5 in (&PTB_all_list.) OR
	DX6 in (&PTB_all_list.) OR
	DX7 in (&PTB_all_list.) OR
	DX8 in (&PTB_all_list.) OR
	DX9 in (&PTB_all_list.) OR
	DX10 in (&PTB_all_list.) OR
	DX11 in (&PTB_all_list.) OR
	DX12 in (&PTB_all_list.) OR
	DX13 in (&PTB_all_list.) OR
	DX14 in (&PTB_all_list.) OR
	DX15 in (&PTB_all_list.)) THEN PTB_birth_line=1; ELSE PTB_birth_line=0;
RUN;

title1 "PTB";
PROC FREQ data=want;
	TABLES PTB_birth_array PTB_birth_line; RUN;

And here are the frequencies:

Wolverine_0-1694027118963.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Array code is incorrect, should be:

 

ARRAY dx_codes DX1-DX15;

PTB_birth_array=0;

do index=1 to dim(dx_codes ); 
    IF dx_codes[index] in: (&PTB_all_list.) THEN PTB_birth_array=1; 
end;

View solution in original post

3 REPLIES 3
Reeza
Super User

Array code is incorrect, should be:

 

ARRAY dx_codes DX1-DX15;

PTB_birth_array=0;

do index=1 to dim(dx_codes ); 
    IF dx_codes[index] in: (&PTB_all_list.) THEN PTB_birth_array=1; 
end;
Wolverine
Quartz | Level 8
Okay, I see it now. If the last variable in the array (DX15) matches the codes in the PTB list, the flag is set to 1. But if DX15 does not match, the flag is set to 0 even if the previous DX vars had already set it to 1.
ballardw
Super User

An alternate:

 

ARRAY dx_codes DX1-DX15;

PTB_birth_array=0;

do index=1 to dim(dx_codes ); 
    IF dx_codes[index] in: (&PTB_all_list.) THEN do;
         PTB_birth_array=1; 
         leave;
    end;
end;

The Leave instruction will terminate the checking after finding the first match.  This might be useful as the Index value will be that of the Dx_codes array element that was first found in the list, potentially very useful if there is some order to the list.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 297 views
  • 3 likes
  • 3 in conversation