Search code examples
sassas-macro

Why does my code inside my macro is not taken into account?


I'm trying to code a macro on SAS that is able to create 50 different sample of 1500 people. But as soon as I enter %macro, all the following code is not taken into account properly (PROC SURVEYSELECT, DATA, RUN... Do not have any color anymore). You'll find below my code, can you please have a look?

%macro loop(50);
%do i=1 %to 50;
    PROC SURVEYSELECT DATA=WORK.TOP_1()
        METHOD=SRS
        OUT= WORK.ALEA_1
        N=1500;
    RUN;
%end;
%mend;
%loop(50);

Solution

  • This is just the usual behaviour of the Enhanced Editor window.

    You should find that when you call your macro the code runs properly, but highlighting isn't applied within the macro definition.

    One workaround is to add the following at the start of your macro definition, on the line after the %macro statement:

    %local DUMMY;
    %let DUMMY = %nrstr(%mend);
    

    This will trick the editor into thinking that it has reached the end of the macro definition without actually having any impact on the code inside the macro, resulting in the highlighting being restored.