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: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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