Tuesday, July 26, 2016

Does keywords _NUMERIC_/_CHARACTER_ represent all numeric/character variables?

Array is my favorite tool. With reserved keywords _NUMERIC_/_CHARACTER_, it can handle dynamic variables list. However, they may not represent all numeric/character variables. When it is in different position of DATA step, it will have different variables list. The codes below shows that array with _NUMERIC_/_CHARACTER_ represents only pre-defined variables. The post-defined variables will not be included anyway.
data _null_;
    array num0{*} _numeric_;

    putlog "Initial numeric array:";
    do i=1 to dim(num0);
        putlog i= num0[i]=;
    end;

    a = 1;
    b= 2;

    array num1{*} _numeric_;
    putlog "First numeric array:";
    do i=1 to dim(num1);
        putlog i= num1[i]=;
    end;

    c = 3;

    array num2{*} _numeric_;
    putlog "Second numeric array:";
    do i=1 to dim(num2);
        putlog i= num2[i]=;
    end;
run;

Result:
Initial numeric array:
First numeric array:
i=1 i=1
i=2 a=1
i=3 b=2
Second numeric array:
i=1 i=1
i=2 a=1
i=3 b=2
i=4 c=3