BookmarkSubscribeRSS Feed
Mike018
Fluorite | Level 6

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;

art297
Opal | Level 21

Are you asking the forum to look at it or are you just letting us know that you now have your desired result?

Mike018
Fluorite | Level 6

It works  Smiley Happy

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 17 replies
  • 11515 views
  • 8 likes
  • 6 in conversation