Wednesday, May 14, 2014

colon(:) operator modifier - Note 1

When string with different length are compared, the colon(:) operator modifier will be very helpful since it truncate longer string before comparison.
However, what is the "length"? Is it the actual length of of a non-blank character string (from LENGTH function)? or the amount of memory that is allocated for the string (from LENGTHM function)?

To clarify the question, please see the sample:
data a;
    length a1 a4 $10;
    a1 = 't';
    a4 = 'test';
    
    flag_a1 = ifc(a1=:'te', 'Y', 'N');
    flag_a4 = ifc(a4=:'te', 'Y', 'N');

    put a1= flag_a1=:;
    put a4= flag_a4=;
run;

Output:
a1=t flag_a1=N  (Explanation: a1 is not truncated because the memory length is 10. the implicit string comparison is 't' = 'te'.)
a4=test flag_a4=Y


Conclusion: the colon(:) operator modifier will truncate the longer string or pad pad with blank the shorter one.

No comments: