BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Mirisage
Obsidian | Level 7

Hi Forum,

Could anyone help me to undestand the red colored piece of this code?

/*Sorting in preparation for "By-group processing" - I understand this  */

PROC SORT DATA=A;

BY ID_NUM;

run;

/*By-group processing- I understand this  */

DATA A1 A2;

   SET A  ;

    

   BY ID_NUM;

   RETAIN LOAN_RECEIVER 0;

   LOAN_RECEIVER + 1; /*Sum statement (not sum function) which returns accumulated total, am I correct?*/

   IF FIRST.ID_NUM THEN LOAN_RECEIVER = 1;

   IF LOAN_RECEIVER = 1 THEN OUTPUT A1;

   ELSE IF LOAN_RECEIVER = 2 THEN OUTPUT A2;

RUN;

Q:

LOAN_RECEIVER + 1; is the Sum statement (not sum function) which returns accumulated total, am I correct?

Thanks

Miris

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

Miris,

The LOAN_RECEIVER + 1; statement is just equivalent to LOAN_RECEIVER = LOAN_RECEIVER + 1;, except for two side effects that are implied by LOAN_RECEIVER being the target of the sum statement. First, LOAN_RECEIVER value is RETAINed from one iteration to the next, second, LOAN_RECEIVER is initialized with zero.

So, you see, the statement RETAIN LOAN_RECEIVER 0; is not needed at all, as both statement's effects are already implied. Try removing it. you should see no change.

PG

PG

View solution in original post

2 REPLIES 2
LinusH
Tourmaline | Level 20

Yes you are correct.The retain statement is unnecessary since variables in a sum statement are retained by default.

Data never sleeps
PGStats
Opal | Level 21

Miris,

The LOAN_RECEIVER + 1; statement is just equivalent to LOAN_RECEIVER = LOAN_RECEIVER + 1;, except for two side effects that are implied by LOAN_RECEIVER being the target of the sum statement. First, LOAN_RECEIVER value is RETAINed from one iteration to the next, second, LOAN_RECEIVER is initialized with zero.

So, you see, the statement RETAIN LOAN_RECEIVER 0; is not needed at all, as both statement's effects are already implied. Try removing it. you should see no change.

PG

PG

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 2 replies
  • 838 views
  • 3 likes
  • 3 in conversation