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;
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;
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;
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.
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!
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.