2

I'm transitioning from SQL Server to SAS.

In SQL server we could get away with string comparisons where 'abc ' = 'aBc' would be true.

Is SAS so far I've had to STRIP and UPPER every string on every comparison.

Is there an option that can be set to allow for 'abc ' = 'aBc' be true ?

My Google-Fu has failed me.

Ben
  • 485
  • 9
  • 19

2 Answers2

4

I believe you are looking for the compare function with the 'i' modifier (for ignore case). When this returns a 0 there's a match.

(See p. 70 in here: http://support.sas.com/publishing/pubcat/chaps/59343.pdf)

data a;
input string1 $ string2 $;
datalines;
abc aBc
cba CBA
AbC ABC
AC  AbC
BCA CAb
;
run;

data b;
set a;
c = compare(string1,string2);
d = compare(string1,string2,'i');
run;
proc print noobs;
where d = 0;
var string1 string2;
run;
3

You can try the PRX functions which use Perl Regular Expressions.

'/abc/i' will match anything with the string 'abc' in any case (because of the 'i' after the closing /)

Using PRXMATCH as an example:

prxmatch('/abc/i', 'aBc') 

Will return 1 as this is the position that string occurs.

More on regular expressions: https://www.cs.tut.fi/~jkorpela/perl/regexp.html

PRX in SAS: http://documentation.sas.com/?docsetId=lefunctionsref&docsetVersion=3.1&docsetTarget=n0bj9p4401w3n9n1gmv6tfshit9m.htm&locale=en

M_CE_A
  • 66
  • 4