首页 > 解决方案 > 无法在宏中执行 Sas INTCK

问题描述

我正在运行以下宏:

%macro diff(yymm);

%let date1=%sysfunc(inputn(strip(putn(&yymm.,yymmn6.))||'01',yymmdd10.));
%let date2=%sysfunc(inputn(strip(putn(201811,yymmn6.))||'01',yymmdd10.));

%let j=%sysfunc(intck(month,&date1.,&date2.));
%put &date1. &date2. &j.;
%mend;
%diff(201807);
%diff(201808);

基本上是为了找出从 18 年 11 月到我作为参数传递给这个宏的任何日期的月份差异。我不确定我哪里出错了,但我收到以下错误:

Argument 1 to function INPUTN referenced by the %SYSFUNC or %QSYSFUNC macro function is out of range.
NOTE: Mathematical operations could not be performed during %SYSFUNC function execution. The result of the operations have been set 
      to a missing value.

有人可以在这里帮助我吗?

标签: datesasmacros

解决方案


YYMMN6。informat 不会被识别strip(为有效的日期值。如果不将每个函数包装在宏函数中,就不能在宏代码中调用函数%sysfunc(),它们看起来就像宏处理器的字母。

这是你想要做的吗?

%macro diff(yymm);
  %put &yymm 201811 %sysfunc(intck(month,%sysfunc(inputn(&yymm, yymmn6.)),'01NOV2018'd));
%mend;

结果:

1104  %diff(201807);
201807 201811 4
1105  %diff(201808);
201808 201811 3

推荐阅读