Friday, September 1, 2017

FINDW with null argument

Few SAS functions can take null argument. Definitely FINDW is special case. It means we can't use default delimiters when it is using modifier. Below is the sample codes and snippet from SAS documentation.
The FINDW function allows character arguments to be null. Null arguments are treated as character strings with a length of zero. Numeric arguments cannot be null.

data _null_;
    str = "aa bb";

    n1 = findw(str, "bb");  * Default deimilters are used;
    n2 = findw(str, "bb", ); * delimiter is NULL character;
    n3 = findw(str, "bb", ' '); * delimiter is blank character;
    n4 = findw(str, "bb", , 'E'); * delimiter is NULL character;
    n5 = findw(str, "bb", , 'SE'); * delimiter is space character, specified by 'S';
    put n1= n2= n3= n4= n5=;
run;

/* Output: n1=4 n2=0 n3=4 n4=0 n5=2*/

No comments: