I have a SAS Logic containing temporary columns (Code et Codep) and an array function and this code I do not understand much , I wanted to translate this SAS Logic in sql server from a SELECT on the table SEL which is already existing, someone can help me to translate this SAS logic in SQL Server, I am blocked
%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;
The code appears to output one row per year when a exer_sin num_sin num_vic combination has at least one operational date in that year.
Something like this