如何将此代码转换为宏? [英] How can I transform this code into macro?

查看:61
本文介绍了如何将此代码转换为宏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我想做一个混合了 proc sql 和 data 步骤的宏代码.我在 SAS 中有以下代码:

So I'd like to do a macro code mixed with proc sql and data step. I have the following code in SAS:

data work.calendar;
set work.calendar;
if business_day_count^=-1 then do;
  num_seq + 1;
  drop num_seq;
  business_day_count = num_seq;
end;
else
  business_day_count = -1;
run;

我想把它放到宏代码中,但它不起作用.

I'd like to put it into macro code, but it doesn't work.

我的宏代码:

%macro1();    
data work.job_calendar;
    set work.job_calendar;
    %if business_day_count^=-1 %then %do;
      num_seq + 1;
      drop num_seq;
      business_day_count = num_seq;
    %end;
    else
      business_day_count = -1;
    run;
%mend;

整个代码是:

%macro update_day(date);

proc sql;
update work.job_calendar
        set business_day_count =
        case when datepart(calendar_date) = "&date"d then -1
        else business_day_count
        end;    
quit;
proc sql;
update work.job_calendar
        set status_ind =
        case when business_day_count = -1 then 'N'
        else status_ind
        end;    
quit;
proc sql;
update work.job_calendar
        set rundate_ind =
        case when business_day_count = -1 then 'N'
        else status_ind
        end;    
quit;
proc sql;
update work.job_calendar
        set daily_rundate_ind =
        case when business_day_count = -1 then 'N'
        else status_ind
        end;    
quit;
proc sql;
update work.job_calendar
        set weekly_rundate_ind =
        case when business_day_count = -1 then 'N'
        else status_ind
        end;    
quit;
proc sql;
update work.job_calendar
        set monthly_rundate_ind =
        case when business_day_count = -1 then 'N'
        else status_ind
        end;    
quit;

data work.job_calendar;
set work.job_calendar;
if business_day_count^=-1 then do;
  num_seq + 1;
  drop num_seq;
  business_day_count = num_seq;
end;
else
  business_day_count = -1;
%mend;

错误代码是:ERROR 180 - 322 语句无效或使用顺序不正确.我不知道我做错了什么.

The error code is: ERROR 180 - 322 Statement is not valid or it is used out of proper order. I don't know what I'm doing wrong.

推荐答案

您正在混合数据步骤和宏代码.不确定您要实现的目标,因此不知道要提出什么建议,但删除 %IF/%THEN 将使您的代码正常工作.

You're mixing data step and macro code. Not sure what you're trying to achieve so no idea on what to propose but removing the %IF/%THEN will allow your code to work.

%macro1();    
data work.job_calendar;
    set work.job_calendar;
    if business_day_count^=-1 then do;
      num_seq + 1;
      drop num_seq;
      business_day_count = num_seq;
    end;
    else
      business_day_count = -1;
    run;
%mend;

%macro1;

这是关于 将工作代码转换为宏整体宏编程.

这篇关于如何将此代码转换为宏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆