I've created a small dataset and I've found where was the problem. I have to increment a variable before I test the LAST.BANK_ID condition. I have put the wrong code in comment.
DATA EXAMPLE;
INPUT TYPE REF_ID BANK_ID NUMBER;
DATALINES;
1 1 1 1003.32
0 2 2 3.89
0 4 2 45.23
1 3 9 5623.02
0 7 6 563.56
1 5 9 714.32
0 9 2 145.32
;
PROC SORT DATA=EXAMPLE;
BY TYPE BANK_ID REF_ID;
RUN;
DATA OUT;
FORMAT SUM COMMA15.2;
FORMAT TEMP COMMA15.2;
FORMAT TYPE_0 1.;
FORMAT TYPE_1 1.;
SET EXAMPLE END=EOF;
BY TYPE BANK_ID REF_ID;
RETAIN SUM 0 TYPE_0 0 TYPE_1 1 TEMP 0 TYPE_0 0 TYPE_1 0;
SUM = 0;
SELECT (TYPE);
WHEN (0,1)
DO;
TEMP = TEMP + NUMBER;
IF LAST.BANK_ID THEN
DO;
SUM = TEMP;
TEMP = 0;
IF LAST.TYPE THEN
DO;
IF TYPE = 0 THEN
DO;
TYPE_0 = SUM(TYPE_0,1);
END;
ELSE IF TYPE = 1 THEN
DO;
TYPE_1 = SUM(TYPE_1,1);
END;
END;
END;
/*ELSE
DO;
TEMP = TEMP + NUMBER;
END;*/
END;
OTHERWISE;
END;
PROC PRINT DATA=OUT;
RUN;
Are you asking the forum to look at it or are you just letting us know that you now have your desired result?
It works
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.