Friday, November 29, 2019

How to loop character A-Z in SAS?

To loop characters A-Z elegantly, we can have two ways as follows:
data _null_;
    put "First method:";
    string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; * string from A to Z;
    do i=1 to length(string);
        char = substrn(string, i, 1);
        put char=; 
    end;

    put "Second method (using RANK and BYTE):";
    do i=rank('A') to rank('Z');
        char = byte(i);
        put char=;
    end;
run;
If you can find any way better, please let me know.

Tuesday, March 26, 2019

How to find hidden macro in batch run

By default, it does not give out any information for macro compilation when the macro definition are %include. It is OK for most time. However, it may be helpful when you want to locate the macro when multiple versions exist. With system option MCOMPILENOTE, we can easily address this problem.
Similarly, we can use MEXECNOTE to get more details on macro execution.

Programmatically, we can add version information in macro description. See blow:
%macro test / des = 'Version 1.0';
%mend;

proc catalog;
contents cat=work.sasmacr; /* list macro description */
quit;