🔒 This topic is solved and locked.
Need further help from the community? Please
sign in and ask a new question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 10-20-2021 03:13 PM
(1345 views)
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;
1 ACCEPTED SOLUTION
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug
"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings
SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug
"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings
SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug
"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings
SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug
"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings
SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
It was late, I was tired, didn't think clearly... 😁😁
All the best
Bart
_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug
"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings
SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug
"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings
SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation