BookmarkSubscribeRSS Feed
Sir_Lancelot
Fluorite | Level 6

I have a field from a source system which is 800 characters long. The target system only allow 80 characters. If the string is more than 80 characters long, I must break it down into multiple records of 80 characters.

 

Please note that the string vary in length. Therefore I must first calculate the length of each record/string.

5 REPLIES 5
Kurt_Bremser
Super User

Brute force attack:

data shortrec (drop=longfield);
set longrec;
length shortfield $80;
do while (length(longfield) > 0);
  shortfield = substr(longfield,1,80);
  output;
  longfield = substr(longfield,81);
end;
run;
FreelanceReinh
Jade | Level 19

 

do while (lengthn(longfield) > 0);

Otherwise, an infinite loop will occur.

 

Kurt_Bremser
Super User

@FreelanceReinh wrote:

 

do while (lengthn(longfield) > 0);

Otherwise, an infinite loop will occur.

 


Correct.

 

I really hate the un-intuitiveness of length() in this regard.

Sir_Lancelot
Fluorite | Level 6

Seems to be running into an infinite loop. See below example string:

 

UPDATED BY : A134906 (BFC PTA:SUPPORT) Current employer: N/A Employer phone number: N/A Source of phone number: BDS Contact last name: N/A Contact first name: N/A Contact designation: N/A Employment restrictions: Basic salary: N/A Payment method: CREDIT TRANSFER COE capture user: A134906 Approved by: A134906