gpt4 book ai didi

sas - 错误 : Required operator not found in expression (SAS)

转载 作者:行者123 更新时间:2023-12-02 16:10:04 26 4
gpt4 key购买 nike

我正在尝试从开始日期和结束日期开始循环,如下所示:

错误:

在表达式中找不到所需的运算符:YEAR(INTNX('MONTH', MDY(2,1,2020), 3, 'SAME'))*100+MONTH(INTNX('MONTH', MDY(2,1 ,2020), 3, '相同'))

代码:

%LET ENDING_YEAR         = 2021;   
%LET ENDING_MONTH = 3;
%LET STARTING_YEAR = 2020;
%LET STARTING_MONTH = 2;

DATA COUNT;
START_DATE = MDY(&STARTING_MONTH.,1,&STARTING_YEAR.);
END_DATE = MDY(&ENDING_MONTH.,1,&ENDING_YEAR.);
COUNT_MONTH = INTCK('MONTH',START_DATE,END_DATE)+1;
COUNT_MONTH_4 = COUNT_MONTH - 4;
COUNT_MONTH_3 = COUNT_MONTH - 3;
call symputx('NUM_MONTH', COUNT_MONTH);
call symputx('NUM_MONTH_4', COUNT_MONTH_4);
call symputx('NUM_MONTH_3', COUNT_MONTH_3);
RUN;


%MACRO FINAL_DATA;
%DO i = 0 %TO &NUM_MONTH_4.;
%LET ADDITION = %EVAL(&i.+3);
%LET TARGET_DB=INTNX('MONTH', MDY(&STARTING_MONTH.,1,&STARTING_YEAR.), &ADDITION., 'SAME');
%LET TARGET_DB_MONTH = MONTH(&TARGET_DB.);
%LET TARGET_DB_YEAR = YEAR(&TARGET_DB.);
%LET DB = %EVAL(&TARGET_DB_YEAR.*100+&TARGET_DB_MONTH.);
LIBNAME TETRIS "/actuary/Commercial/Monthend/&DB.";
%LET TARGET_EFF =INTNX('MONTH', MDY(&STARTING_MONTH.,1,&STARTING_YEAR.), &i., 'SAME');
%LET TARGET_EFF_MONTH = MONTH(&TARGET_EFF.);
%LET TARGET_EFF_YEAR = YEAR(&TARGET_EFF.);
%EXTRACTION(INFORCE, &TARGET_EFF_YEAR.,&TARGET_EFF_MONTH.);
%END;

%DO j = &NUM_MONTH_3. %TO &NUM_MONTH.;
%LET DB = %EVAL(&ENDING_YEAR.*100+&ENDING_MONTH.);
LIBNAME TETRIS "/actuary/Commercial/Monthend/&DB.";
%LET TARGET_EFF =INTNX('MONTH', MDY(&STARTING_MONTH.,1,&STARTING_YEAR.), &j., 'SAME');
%LET TARGET_EFF_MONTH = MONTH(&TARGET_EFF.);
%LET TARGET_EFF_YEAR = YEAR(&TARGET_EFF.);
%EXTRACTION(INFORCE, &TARGET_EFF_YEAR.,&TARGET_EFF_MONTH.);
%END;

%MEND;

%FINAL_DATA;

我是 SAS 新手。任何建议将不胜感激。

谢谢。

最佳答案

如果您想在宏逻辑中调用 YEAR() 或 INTNX() 等 SAS 函数,则每个函数调用都需要使用 %SYSFUNC() 宏函数来调用 SAS 函数。

所以在这个声明中:

%LET DB = %EVAL(&TARGET_DB_YEAR.*100+&TARGET_DB_MONTH.);

因为被引用的宏变量有这样的字符串:

TARGET_DB_YEAR resolves to YEAR(INTNX('MONTH', MDY(2,1,2020), 3, 'SAME'))
TARGET_DB_MONTH resolves to MONTH(INTNX('MONTH', MDY(2,1,2020), 3, 'SAME'))

SAS 用于存储日期值的不是自 1960 年以来的实际天数,而是要求 %eval() 函数执行它无法理解的操作。它只能做简单的整数运算和 bool 逻辑。

要遍历一系列月份,只需使用 INTNX() 函数使用起始月份的偏移量。如果要生成 YYYYMM 数字字符串,只需使用 YYMMN 格式即可。

所以你可以使用这样的东西:

%let start=%sysfunc(mdy(&starting_month,1,&starting_year));
%let end=%sysfunc(mdy(&ending_month,1,&ending_year));
%do offset = 0 %to %sysfunc(intck(month,&start,&end));
%let date=%sysfunc(intnx(month,&start,&offset));
%let db=%sysfunc(putn(&date,yymmn6.));
...
%end;

关于sas - 错误 : Required operator not found in expression (SAS),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68250686/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com