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
Amethyst | Level 16

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
Amethyst | Level 16

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
Amethyst | Level 16

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



hackathon24-white-horiz.png

Join the 2025 SAS Hackathon!

Calling all data scientists and open-source enthusiasts! Want to solve real problems that impact your company or the world? Register to hack by August 31st!

Register Now

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1037 views
  • 2 likes
  • 3 in conversation