I am trying to search an array for certain criteria. I want to find all codes starting with "C", excluding those lines where the only type is one that starts with "C44". In a previous question someone helped me solve a similar issue.
https://communities.sas.com/t5/SAS-Programming/Looking-for-Like-Values-in-Array/m-p/763300
The difference being now I'm trying to add in some more specific logic to filter out a subcase ("C44")
data have;
input code1 $ code2 $ code3 $;
datalines;
C334 C446 F213
F321 Y758 I893
C333 F231 F792
C446 F333 F334
F032 U234 F335
C430 R456 C456
;
run;
data want;
input code1 $ code2 $ code3 $ flag;
datalines;
C334 C446 F213 1
F321 Y758 I893 0
C333 F231 F792 1
C446 F333 F334 0
F032 U234 F335 0
C430 R456 C456 1
;
run;
Like that:
data have;
input code1 $ code2 $ code3 $;
datalines;
C334 C446 F213
F321 Y758 I893
C333 F231 F792
C446 F333 F334
F032 U234 F335
C430 R456 C456
;
run;
data want;
set have;
array C code:;
call missing(a, b); drop a b;
do over C;
/*
a + ifn(C =: "C",1,0);
b + ifn(C =: "C44",1,0);
*/
/* thanks @PeterClemmensen ! :-) */
a + (C =: "C");
b + (C =: "C44");
end;
flag = a > b;
run;
proc print data = want;
run;
?
Bart
Like that:
data have;
input code1 $ code2 $ code3 $;
datalines;
C334 C446 F213
F321 Y758 I893
C333 F231 F792
C446 F333 F334
F032 U234 F335
C430 R456 C456
;
run;
data want;
set have;
array C code:;
call missing(a, b); drop a b;
do over C;
/*
a + ifn(C =: "C",1,0);
b + ifn(C =: "C44",1,0);
*/
/* thanks @PeterClemmensen ! :-) */
a + (C =: "C");
b + (C =: "C44");
end;
flag = a > b;
run;
proc print data = want;
run;
?
Bart
It was late, I was tired, didn't think clearly... 😁😁
All the best
Bart
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.