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?
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.
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.
Exactly what I wanted! Thank you very much!
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 to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.
Find more tutorials on the SAS Users YouTube channel.