top of page
Macros

%DO Iterative Statement

Examples:

%MACRO mloop;

    %DO x1=1 %TO &x2;

        %GLOBAL &x1;

        %LET &x1='texto';

       

        DATA dateset1;

        SET dataset1;

            IF name='valor';

        RUN;

    %END;

%MEND mloop;

%mloop;

%LET

Examples:

 

  • Create a file with macro commands

 

%LET filetf = 'C:\...\file.txt';

 

DATA _NULL_;

SET dataset (KEEP=x1 x2, ...);

WHERE x1='valor';

FILE &filetf;

PUT '%macro_name(' x1 ' , ' x2 ' , ...);';

RUN;

%MARCO

Examples:

  • ​Having numbers in text format create new variables in numeric format using a macro inside a datastep

DATA dataset2;

SET dataset1;

%MACRO macro_name(x1, ...);

    FORMAT c&x1 12.;

        c&x1=&x1;

    DROP &x1;

%MEND;

%INC &filetf;

RUN;

  • Execute a macro based on a SAS table

%MACRO macro_name(x1, ...);

    ...

%MEND;

DATA _NULL_;

SET dataset1;

CALL EXECUTE( "%macro_name(" || x1 || ");" );

RUN;

%DO Iterative Statement
%LET
%MARCO

© 2021 Jorge Pinheiro

bottom of page