petertang1006 2021-07-21 09:27 采纳率: 0%
浏览 25

SAS 运行出错,function datepart 出错

我连接SQL SERVE提取数据,其中有日期变量,运行代码,总是出现错误
日志如下

3    %let begDt='01JAN18'd;
4    %let endDt='31DEC18'd;
5
6
7    proc format;
8    value n357_fmt
9        low-15      = 'Within 15 days'
10       15<-high    = 'After 15 days'
11       .           = 'Not Completed';
NOTE: Format N357_FMT has been output.
12   value n358_fmt
13       low-30      = 'Within 30 days'
14       30<-high    = 'After 30 days'
15       .           = 'Not Completed';
NOTE: Format N358_FMT has been output.
16   run;

NOTE: PROCEDURE FORMAT used (Total process time):
      real time           0.02 seconds
      cpu time            0.03 seconds




41   %macro nTrigEvent(lbl,n,days,trigKey,trigCrit,trigDate,trigTbl,evntDate,evntTbl,jnCrtr);
42       proc sql;
43           create table n&n. as
44           select x.clientID, max(x.daysTo&days.) as n&n._daysTo&days. label="&lbl.: Days To
44 ! &days."
45           from
46               (select a.clientID, a.&trigKey., datepart(b.&evntDate.)-datepart(a.&trigDate.)
46 ! as daysTo&days.,
47                       abs(datepart(b.&evntDate.)-datepart(a.&trigDate.)) as abs_daysTo&days.
48                from kntt.&trigTbl. as a
49                    left join kntt.&evntTbl. as b
50                       on %unquote(&jnCrtr.)
51                where &begDt. le datepart(a.&trigDate.) le &endDt. &trigCrit.
52                group by a.clientID, a.&trigKey.
53                having min(abs(datepart(b.&evntDate.)-datepart(a.&trigDate.)))=calculated
53 ! abs_daysTo&days.) as x
54           group by x.clientID
55           order by x.clientID;
56       quit;
57   %mend nTrigEvent;
58

68   %nTrigEvent(lbl=3.4.2,n=342, days=mfpQ, trigKey=AuditDocumentID, trigCrit=%str(and
68 ! a.AuditDocumentID like 'applicationpackets%%' and a.StatusToDisplayName='Submitted'),
69       trigDate=CreatedTimestamp, trigTbl=auditTrail, evntDate=ConsentFormDate,
69 ! evntTbl=mfpQuestionnaire,
70       jnCrtr=%nrstr(a.clientID=b.clientID and WorkflowStatusDisplayName='Submitted'))



```c
ERROR: Function DATEPART requires a numeric expression as argument 1.
ERROR: Expression using subtraction (-) requires numeric types.
ERROR: Function DATEPART requires a numeric expression as argument 1.
ERROR: Expression using subtraction (-) requires numeric types.
ERROR: Function DATEPART requires a numeric expression as argument 1.
ERROR: Expression using subtraction (-) requires numeric types.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.08 seconds
      cpu time            0.01 seconds





改了很多次,都失败

Datepart 后变变量应该是日期,但从SQL出来的日期好像不是DATE FORMAT。我加了INPUT,但又出错。 因为变量好像是宏

Function DATEPART requires a numeric expression as argument 1.代码里的宏


```c
%nTrigEvent(lbl=3.4.2,n=342, days=mfpQ, trigKey=AuditDocumentID, trigCrit=%str(and a.AuditDocumentID like 'applicationpackets%%' and a.StatusToDisplayName='Submitted'),
        trigDate=CreatedTimestamp, trigTbl=auditTrail, evntDate=ConsentFormDate, evntTbl=mfpQuestionnaire,
        jnCrtr=%nrstr(a.clientID=b.clientID and WorkflowStatusDisplayName='Submitted'))

  • 写回答

1条回答 默认 最新

      报告相同问题?

      相关推荐 更多相似问题

      问题事件

      • 创建了问题 7月21日

      悬赏问题

      • ¥15 easyclick重启app
      • ¥15 ros系统里Python版本问题
      • ¥15 不兼容驱动程序删不了,内核隔离打不开
      • ¥15 Centos7重启网卡自动down,只能手动up
      • ¥15 multisim用74ls148做一个5号病号呼叫系统
      • ¥15 单片机,传感器,LCD1602
      • ¥15 关于adams 批处理仿真时间太长的问题
      • ¥15 fate部署问题请求帮助
      • ¥15 关于#arcpy#的问题:arcpy栅格计算器批处理(语言-python)
      • ¥15 stata logit的备选项自变量不同