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

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
yabwon
Onyx | Level 15

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



View solution in original post

3 REPLIES 3
yabwon
Onyx | Level 15

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



PeterClemmensen
Tourmaline | Level 20

@yabwon why not just

 

  a + (C =: "C");
  b + (C =: "C44");

? 🙂

yabwon
Onyx | Level 15

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



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
  • 3 replies
  • 628 views
  • 2 likes
  • 3 in conversation