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.
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;
do while (lengthn(longfield) > 0);
Otherwise, an infinite loop will occur.
@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.
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
As mentioned by @FreelanceReinh, use lenghtn() instead of length().
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.