unix - SAS 在 Unix 服务器上定义宏
问题描述
您好我正在尝试在 Unix 服务器上定义和运行 SAS 宏。
options symbolgen mprint mlogic;
*options nosymbolgen nomprint nomlogic;
rsubmit;
%let trend_MM = 1;
%let run_date = &sysdate.;
/* loop through Trend_MM number of times to retrieve the MTR completed per each month. */
%macro Trend();
%local start_dt;
%local end_dt;
%local i;
/* loop through each month */
%do i = &Trend_MM. %to 0 %by -1;
/* Calculate set start/end dates to start/end of month */
%let start_dt = %qsysfunc(intnx(month,"&run_date."d,%eval(-1*&i.),b),date9.);
%let end_dt = %qsysfunc(intnx(month,"&run_date."d,%eval(-1*&i).,e),date9.);
/* select MTR claims in month */
proc sql;
create table MTR_&i. as
select a.claim_id_360
,a.claim_id_external
,a.timestamp
/* v02: a) export date part of the timestamp */
,datepart(a.timestamp) as timestamp_dt
,a.status_data
,a.status_label
,a.RFE_template_name
,a.brand_name
,case when b.claim_id_360 is not missing then "Y" else "N" end as MTR_compl
,c.MTR_count
,b.last_MTR_comp format = ddmmyy10.
from
/* Base population are all claims where final status is not */
(
select distinct *
from allg360r._travel_rfe_state_change_hist
(keep = claim_id_360 claim_id_external timestamp status_data status_label RFE_template_name brand_name)
where datepart(timestamp) between "&start_dt."d and "&end_dt."d
group by claim_id_360
having timestamp = max(timestamp) and strip(upcase(status_label)) ne "Move to Review"
) a
left join
/* subset with claims that have had a status in the reference period to obtain */
/* claims that have had such status completed in the period. */
/* Also retrieve date of last MTR completed */
(
select distinct claim_id_360, datepart(timestamp) as last_MTR_comp
from allg360r._travel_rfe_state_change_hist
(keep = claim_id_360 claim_id_external timestamp status_data status_label RFE_template_name brand_name)
where (datepart(timestamp) between "&start_dt."d and "&end_dt."d) and status_label = "Move to Review"
group by claim_id_360
having timestamp = max(timestamp)
) b
on a.claim_id_360 = b.claim_id_360
left join
/* Add count of how many since inception of claim */
/* v02: b) count how many times in MTR since beginning */
(
select distinct
claim_id_360
,count(claim_id_360) as MTR_count
from allg360r._travel_rfe_state_change_hist
(keep = claim_id_360 claim_id_external timestamp status_data status_label RFE_template_name brand_name)
where status_label = "Move to Review"
group by claim_id_360
) C
on a.claim_id_360 = c.claim_id_360
;
quit;
/* create/append to dataset of all months */
%if &i. = &trend_MM. %then
%do;
proc sql;
drop table work.MTR;
create table work.MTR like work.MTR_&i.;
quit;
%end;
proc append base = work.MTR data = work.MTR_&i.;
run;
%end;
%mend Trend;
%trend
endrsubmit;
它似乎工作正常,但我在日志中不断收到此错误:
第995章 ---------- 180
错误 180-322:语句无效或使用顺序不正确。
如果我在宏调用后加上分号,错误似乎消失了。这对我来说没有意义,因为宏以运行结束;并在调用后加上分号应该没有任何区别。
任何想法为什么会发生这种情况?
解决方案
原因是 - 你用括号定义了你的宏()
在调用中添加一些括号,它将在没有分号的情况下执行。
%trend()
推荐阅读
- ignite - Apache Ignite 如何在 K8S 中部署?
- database - ClickHouse 函数中的第二个参数 toDateTime64 是什么意思?
- python - 如何使用 python reduce 函数填充 NaN 值
- java - 将 ZonedDatetime 转换为字符串
- git - 尝试初始化合并请求源时,Repo init 失败
- python - 如何比较字典值和熊猫数据框?
- android - 如何处理android单活动设计模式中的片段?
- date - 在 oracle 中为选择查询结果日期添加天数
- c - scanf("%d/%d%c%d/%d", &num1, &denom1, &sign, &num2, &denom2); 继续在控制台扫描用户输入
- flutter - 如何获得未来的权利
>> 在颤振中?