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

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!

Register now

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 5 replies
  • 1515 views
  • 0 likes
  • 3 in conversation