BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
rbettinger
Lapis Lazuli | Level 10

I have two character vectors. Let's call them Source and Pattern. For each entry in Pattern, I want to know if it is represented in Source. Here is an example:

----------

Pattern = 'trapmf' // 'trimf' // 'pimf' ;
Source = 'dsigmf' // 'trapmf' // 'pimf' // 'gaussmf' ;

print Pattern Source ;

do i = 1 to nrow( Pattern ) ;
Match = any( Pattern[i] = Source ) ;
print Match ;
end ;

----------

Then the expected results are: Match = 1,0, 1 as expected. But I have to use a loop, which I consider to be inelegant. How can I use SAS/IML matrix manipulation to create an "outer product" character match?

1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

Use the ELEMENT function:

b = element(Pattern, Source);
print b;

BTW, that performs a case-sensitive comparison. If you want a case-insensitive comparison, use the UPCASE function.

View solution in original post

2 REPLIES 2
Rick_SAS
SAS Super FREQ

Use the ELEMENT function:

b = element(Pattern, Source);
print b;

BTW, that performs a case-sensitive comparison. If you want a case-insensitive comparison, use the UPCASE function.

rbettinger
Lapis Lazuli | Level 10

Exactly what I wanted! Thank you very much!

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

From The DO Loop
Want more? Visit our blog for more articles like these.
Discussion stats
  • 2 replies
  • 919 views
  • 0 likes
  • 2 in conversation