BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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 ;
8 REPLIES 8
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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
deleted_user
Not applicable
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.
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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.
deleted_user
Not applicable
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.
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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.
deleted_user
Not applicable
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.
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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
Flip
Fluorite | Level 6
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 .

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 8 replies
  • 1094 views
  • 0 likes
  • 3 in conversation