user7108488
user7108488

Reputation: 19

how to call multiple macros using sas autos

hello i have generic macros for specific tasks how can I automatically call a macro & the corresponding macro is compiled and executed.. i tried running a defined macro in the log and then calling the specific macro call but its to slow, but can anybody provide another solution to automatically executing the macro when i run the required macro call... thanks in advance.

below is location off my macro--> F:\SAS\BI\macro

below are my sample macro in the location-->

%macro rand(dsn1=,dsn2=,odsn=);
Data &dsn1;
    do i=1 to 27;
        t=rand("uniform")*40;
    do j=1 to 10;
        w=rand("uniform");
        bj=0.2;
        sigma=0;
        sigma+(t*w)+bj;
        y=1/(1+exp(-sigma));    
        output;
    end;
    end;
run;

Data &dsn2;
    set &dsn1(keep=y);
    do j=1 to 10;
        *y=y;
    do k=1 to 5;
        w2=rand("uniform");
        bk=0.3;
        sigma2=0;
        sigma2+(y*w2)+bk;
        z=1/(1+exp(-sigma2));   
        output;
    end;
    end;
run;

data &odsn;
    set &dsn1 &dsn2;
run;
%mend;
%rand(dsn1=numerics.itoh,dsn2=numerics.htoo,odsn=numerics.itoo);

Upvotes: 0

Views: 1269

Answers (2)

Tom
Tom

Reputation: 51601

If you want to use autocall macros then the file should only include the macro definition and not the macro call that is on the last line of the code you posted. Also the file name should be the macro name with the extension .sas. So in this case the filename should be rand.sas. If you running SAS on unix then the filename must be in all lowercase.

You just need to add the path for where the files with the macro definitions are stored to the setting for the SASAUTOS option. Then you can call the macro anywhere you want in your SAS program.

 options sasautos=('F:\SAS\BI\macro\',sasautos);
 %rand(dsn1=numerics.itoh,dsn2=numerics.htoo,odsn=numerics.itoo);

Upvotes: 0

user667489
user667489

Reputation: 9569

If your goal is to avoid recompiling macros saved in your folder every time you use them, you should be able to achieve this by setting option sasautos="F:\SAS\BI\macro";. Provided that each macro you want to use is saved in a separate .sas file with the same name as the macro, that should work.

If you are using a suitably modern version of SAS, then go with RawFocus's suggestion instead, as this preserves any existing sasautos settings.

options insert=(sasautos="F:\SAS\BI\macro");

This still might cause some changes in macro behaviour if you have macros with the same name in your new folder and any of your existing sasautos folders.

Upvotes: 1

Related Questions