DATA Step, Macro, Functions and more

Usage of Do Until in DATA Step... question

Reply
N/A
Posts: 0

Usage of Do Until in DATA Step... question

I need help to understand what the code below is doing ?
The Do Until () together with group by loan_id is what is confusing me mainly...

Thanks in advance.

Code:

data fccont_duration2 ( keep = loan_id dur ) ;
length distr $ 32767 ;
do until ( last.loan_id ) ;
set fccont_duration ;
by loan_id ;
if end_dt > start_dt then
substr (distr, 5373 + start_dt, end_dt - start_dt + 1) = repeat
('1', end_dt - start_dt) ;
else
substr (distr, 5373 + start_dt , 1) = '1' ;
end ;
dur = length (compress (distr)) ;
run ;
Super Contributor
Super Contributor
Posts: 3,174

Re: Usage of Do Until in DATA Step... question

Posted in reply to deleted_user
Suggest you add a SAS command for more diagnostics inside the DO loop (for more than one, increment "nnn" below):

PUTLOG '>DIAG-nnn>' / _all_;

This additional info in your SAS log will show you when you have LOAN_ID conditions such as LAST.LOAN_ID.

Also, suggest you read up on BY GROUP PROCESSING.

Scott Barry
SBBWorks, Inc.

Suggest Google advanced search argument, this topic/post:

by group processing site:sas.com
N/A
Posts: 0

Re: Usage of Do Until in DATA Step... question

Thanks for your reply Scott, but unfortunately I do not have a way to debug SAS Code, that's why I was requesting to get a brief explanation on what that code is doing.

I am not a beginner to SAS, but that piece of code is above my skill set.

I will greatly appreciate if someone can explain what that working piece of code is doing.
Super Contributor
Super Contributor
Posts: 3,174

Re: Usage of Do Until in DATA Step... question

Posted in reply to deleted_user
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.

Scott Barry
SBBWorks, Inc.
N/A
Posts: 0

Re: Usage of Do Until in DATA Step... question

Posted in reply to deleted_user
Scott/Someone, can you please tell me what the following line of code is doing? I do know what the substr and repeat functions do. Just want to know the significance of 5373...

I am asking this because I have to recreate this same logic in Oracle.


substr (distr, 5373 + start_dt, end_dt - start_dt + 1) = repeat ('1', end_dt - start_dt) ;


Thanks in advance.
Super Contributor
Super Contributor
Posts: 3,174

Re: Usage of Do Until in DATA Step... question

Posted in reply to deleted_user
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.

Scott Barry
SBBWorks, Inc.
N/A
Posts: 0

Re: Usage of Do Until in DATA Step... question

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.

If you can enlighten me on this plz.
Super Contributor
Super Contributor
Posts: 3,174

Re: Usage of Do Until in DATA Step... question

Posted in reply to deleted_user
Suggested reading up on SAS DATEs - link below.

Scott Barry
SBBWorks, Inc.

http://support.sas.com/documentation/cdl/en/basess/58133/HTML/default/a001304321.htm

Suggested Google advanced search argument, this topic/post:

using sas dates site:sas.com
Super Contributor
Posts: 359

Re: Usage of Do Until in DATA Step... question

Posted in reply to deleted_user
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 .
Ask a Question
Discussion stats
  • 8 replies
  • 241 views
  • 0 likes
  • 3 in conversation