我有一个包含临时列(Code et Codep)和一个数组函数的 SAS 逻辑,这个代码我不太理解,我想从已经存在的表 SEL 上的 SELECT 翻译 sql server 中的这个 SAS 逻辑,有人可以帮我在SQL Server中翻译这个SAS逻辑,我被屏蔽了
%let YEAR=2023;
%macro SORTIES(dat_obs);
proc sort data=SEL_MFCFINAN out=SEL; by exer_sin num_sin num_vic descending dat_oper descending num_mvt; run;
data SEL;
set SEL;
by exer_sin num_sin num_vic descending dat_oper descending num_mvt;
array code(%eval(&YEAR-2013+1));
array codep(%eval(&YEAR-2013+1));
retain code codep;
format Date ddmmyy10.;
if first.num_vic then do;
do i=1 to %eval(&YEAR-2013+1);
code(i)='0';
codep(i)='0';
end;
end;
%do j=&YEAR %to 2013 %by -1;
Date="31DEC&j"d;
if dat_oper<=Date and code(%eval(&j-2013+1))='0' then do;
code(%eval(&j-2013+1))='1';
sit='F';
output;
end;
%end;
drop code1--code%eval(&YEAR-2013+1) codep1--codep%eval(&YEAR-2013+1) i;
run;
%mend SORTIES;
%SORTIES;
当 exer_sin num_sin num_vic 组合在该年至少有一个运行日期时,代码似乎每年输出一行。
类似这样的事情
create table want as
select exer_sin, num_sin, num_vic, year(oper_dat) as year, 'F' as sit
from have
group by exer_sin, num_sin, num_vic, year(oper_dat)
having count(dat_oper) > 0