DATA Step, Macro, Functions and more

RETAIN will not retain

Reply
Contributor
Posts: 39

RETAIN will not retain

Can't figure out why the retain statement will not hold the value of holdbroke or brokefound.
Can someone explain why?

The idea of the code is to capture the month when delbnd is greater than or equal to 3, and place it on ever subsequent record for the customer.


data forbearance3;
retain holdbroke;
retain brokefound 0;
holdbroke=.;
set forbearance2;
by cust_no asofmonth;
if first.cust_no then do; brokefound=0; conbrokemon=.; end;

if brokefound=0 then do;
if delbnd>=3 then do;
holdbroke=asofmonth;
brokefound=1;
end;
else;

end;

if brokefound=1 then do;
conbrokemon=holdbroke;
end;
run;
Super Contributor
Super Contributor
Posts: 3,174

Re: RETAIN will not retain

You have code that assigns a missing value with every DATA step pass. Suggest you might want to add this line of code for self-debugging and some desk-checking of your program (add multiple occurences and assign unique nn to keep track where your program is generating the diagnostic messages to the SAS log):

PUTLOG '>DIAG-nn' / _ALL_;


Scott Barry
SBBWorks, Inc.

Suggested Google advanced search argument, this topic/post:

data step programming retain statement site:sas.com
Contributor
Posts: 39

Re: RETAIN will not retain

Thanks. To be honest, even though I've been looking at the code, trying to figure the problem out, I did not even notice that statement was still there!!
Super Contributor
Super Contributor
Posts: 3,174

Re: RETAIN will not retain

Using the PUTLOG (new with SAS v9, previously used PUT with FILE LOGSmiley Wink will help with the condition - it helps me all the time and I've been using SAS for 25+ years.

Scott
Ask a Question
Discussion stats
  • 3 replies
  • 131 views
  • 0 likes
  • 2 in conversation