The DATA step only returns to the top with each new LOANID value - the DO UNTIL (); END; continues processing each new observation until the condition LAST.LOANID occurs -- which sets a SAS-maintained variable to a 1. Then your DATA step drops out of the DO / END and continues with the remaining code. Then it returns to the top of the DATA step.
Still suggest you review the BY GROUP PROCESSING DOC which is quite pertinent.
And, honestly, I fully expect that you could cook up some instream data using DATALINES to simulate the process quite easily, if you really want to learn what's going on.
When the SUBSTR is on the left-side of a SAS variable assignment statement, it means that a SAS CHARACTER variable is being manipulated at the offset (and for the specified length, or to the end if length is not coded). The function to the right is substituting '1' for the substring field being manipulated, based on the calculated difference between two dates.
Thanks Scott. But, like I said in my post, I know what the SUBSTR and REPEAT functions do. I wanted to know what happens when 5373 is added to Start_Date. I know that SAS has some crap logic of counting all the dates from 1-Jan-1960.
The code is generating as count of active days. I assume that the first 5373 characters of the long string have already been assigned in a prior data step. a '1' is set to each charcater following that point in the string if it is between the start and stop date. Each character possition represents a given day. Then the length is the count of days.
Beyond that we would need to know the contnts of fccont_duration .