无法调用宏 - 错误 180-322:语句无效或未按正确顺序使用

问题描述 投票:0回答:1
%macro g;
    proc sql outobs=1;
        create table working_day as 
            select max(calendar_date9) format date9. as WK_day, 
                   (select cur_date from cur_date) as current_date format date9.
            from rank_job_calendar_list_s1 
            where (calendar_date9 <= (select cur_date from cur_date)) and rundate_ind = 'Y';
    quit;

    proc sql;
        select WK_day into: work_day from working_day;
    quit;

    %put &work_day.;
%mend gg;

data rank_job_calendar_list_due(keep=calendar_date calendar_date9 rundate_ind rank due_day_rank);
    set rank_job_calendar_list_s1(where=(rundate_ind = 'Y' and weekday(datepart(calendar_date)) \< 7));

    if calendar_date9="&cur_date."d then due_day_rank=rank +44;

    else if calendar_date9^="&cur_date."d then %gg;
run;
sql error-handling sas macros sas-macro
1个回答
0
投票

您编写的代码无法工作,因为宏是代码生成器,而不是代码执行器。 它生成一个 PROC SQL 步骤,但最终您的 DATA 步骤会尝试调用 PROC SQL 步骤,但这是行不通的。

在这种情况下,运行 PROC SQL 步骤来创建宏变量,然后在 DATA 步骤中使用宏变量会更容易,例如:

proc sql outobs=1;
    create table working_day as 
        select max(calendar_date9) format date9. as WK_day, 
                   (select cur_date from cur_date) as current_date format date9.
        from rank_job_calendar_list_s1 
        where (calendar_date9 <= (select cur_date from cur_date)) and rundate_ind = 'Y';
quit;

proc sql;
    select WK_day into: work_day from working_day;
quit;

%put &work_day.;


data rank_job_calendar_list_due(keep=calendar_date calendar_date9 rundate_ind rank due_day_rank);
    set rank_job_calendar_list_s1(where=(rundate_ind = 'Y' and weekday(datepart(calendar_date)) \< 7));

    if calendar_date9="&cur_date."d then due_day_rank=rank +44;

    else if calendar_date9^="&cur_date."d then &work_day;
run;
最新问题
© www.soinside.com 2019 - 2024. All rights reserved.