我可以在SAS中更改CALL EXECUTE堆栈的执行顺序吗?

chu*_*son 2 sas sas-macro

我正在使用SAS 9.1.3在DATA步骤中调用一个宏,但宏生成一个PROC REPORT步骤,所以我使用CALL EXECUTE来调用它,生成所有这些PROC REPORT步骤,然后在所有这些步骤之后执行它们.数据步骤.

我正在使用一个数组,每次为这个数组中的每个元素执行宏:

DATA macro_test;
  ARRAY questions[3] $ 32 ('question1' 'question2' 'question3');

  DO i=1 to 3;
    a_question = questions(i);
    CALL EXECUTE( "%report_by_question(a_question)" ); 
  end;

RUN;
Run Code Online (Sandbox Code Playgroud)

问题是,报告输出(通常)向后 - 它将首先打印问题3,然后打印2,然后打印1.

有没有办法修改CALL EXECUTE的执行顺序,这样我可以按顺序打印问题报告,还是只做自己的事情?

谢谢!

Sim*_*son 5

我认为你的意思更像你的call execute()行:

 CALL EXECUTE( "%report_by_question(" || trim(left(a_question)) || ");" ); 
Run Code Online (Sandbox Code Playgroud)

使用测试宏我得到一些这样的日志行,表明call execute()s正在以正确的顺序发生.你有类似的东西吗?

%macro report_by_question(a);
data test_&a;
  do i=1 to 10000000;
    output;
  end;
run;
%mend;
Run Code Online (Sandbox Code Playgroud)

日志

NOTE: CALL EXECUTE generated line.
1   + data test_question1;   do i=1 to 10000000;     output;   end; run;

NOTE: The data set WORK.TEST_QUESTION1 has 10000000 observations and 1 variables.
NOTE: DATA statement used (Total process time):
      real time           6.14 seconds
      cpu time            0.45 seconds


1   +                                                                   ;
2   + data test_question2;   do i=1 to 10000000;     output;   end; run;

NOTE: The data set WORK.TEST_QUESTION2 has 10000000 observations and 1 variables.
NOTE: DATA statement used (Total process time):
      real time           3.87 seconds
      cpu time            0.53 seconds


2   +                                                                   ;
3   + data test_question3;   do i=1 to 10000000;     output;   end; run;

NOTE: The data set WORK.TEST_QUESTION3 has 10000000 observations and 1 variables.
NOTE: DATA statement used (Total process time):
      real time           3.12 seconds
      cpu time            0.45 seconds