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

HI Folks:

I'm trying to identify cases based on the array which consists of 25 variables initialized with DX in my data. The variable IDENTIFIED is the correct answer in the HAVE data where the IDENTIFIED variable correctly captured value of '157' in any variable of the array. In other words, all DX01-DX03 are diagnoses and any of this series of variables can indicate the diagnosis (157 by ICD-9) that I'm looking up to identify. 

 

Thanks for your time in advance.  

data HAVE;
  input DX01 $ DX02 $ DX03 $ IDENTIFIED;
cards;
157 157 200 1
157 200 100 1
100 157 100 1
;
data WANT; set HAVE;
  array DXIN [3] DX01-DX03;
  do I = 1 to dim(DXIN);
	 IDENTIFY=DXIN[I]='157';
  end;
  drop I; 
run;

 

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

Take a look at the Whichc Function

 

data HAVE;
  input DX01 $ DX02 $ DX03 $;
cards;
157 157 200
157 200 100
100 157 100
100 100 100
;

data WANT; 
  set HAVE;
  array DXIN [3] DX01-DX03;
  identify = whichc('157', of DXIN[*]) > 0;
run;

View solution in original post

4 REPLIES 4
PeterClemmensen
Tourmaline | Level 20

Take a look at the Whichc Function

 

data HAVE;
  input DX01 $ DX02 $ DX03 $;
cards;
157 157 200
157 200 100
100 157 100
100 100 100
;

data WANT; 
  set HAVE;
  array DXIN [3] DX01-DX03;
  identify = whichc('157', of DXIN[*]) > 0;
run;
Cruise
Ammonite | Level 13
Very useful function it is. Thank you!
novinosrin
Tourmaline | Level 20

Hi @Cruise  Good morning, This is a nice scenario to utilize a Boolean (1,0) operation using the IN operator. IN works typically like a check function/method 

 

data HAVE;
  input DX01 $ DX02 $ DX03 $ IDENTIFIED;
cards;
157 157 200 1
157 200 100 1
100 157 100 1
;

data want;
 set have;
 array t DX01- DX03;
 IDENTIFY='157' in t;
run;

If value in array then return 1 else return 0.

 

Cruise
Ammonite | Level 13
Thanks a lot. I ended up using IN function.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 858 views
  • 6 likes
  • 3 in conversation