Date: Tue, 2 May 2000 13:54:45 -0400
Reply-To: Michael Bramley-M <bramley.m@PG.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Michael Bramley-M <bramley.m@PG.COM>
Subject: Re: breaking up a 200 character field
Content-type: text/plain; charset=us-ascii
SAS-L:
May I suggest that you re-think the limit of 4 character variables of 50 bytes
each, as I discovered quite quickly that under the above restraints, you will
more than likely end up breaking up the original string into bits < 50 bytes,
hence requiring one extra variable.
The following code performs the task at hand (breaks up on word boundaries, <=
50 bytes)
but may require verification on a larger dataset. I used this string, but a
sample size of
one has no real power.
HTH,
Michael
Data Temp ;
Length Temp $51 A1-A5 $50 ;
Array Chrs{5} A1-A5 ;
X = "The following code performs the task at hand (breaks up on word
boundaries, <= 50 bytes)
but may require verification on a larger dataset. I used this string, but a
sample size of
one has no real power." ;
Idx = 1 ;
Do While(Length(X) > 50 ) ;
/* find position of last space, before the end (50 bytes) */
Temp = Reverse(SubStr(X,1,51)) ;
J = Index(Temp, ' ') ;
J = 50 - J + 1 ;
/* stuff this extract into the character array */
/* and continue with rest of original string */
Chrs{Idx} = SubStr(X,1,J) ;
X = SubStr(X,J+1) ;
Idx + 1 ;
End ;
/* fall out of loop, so update array with last bit of text. */
Chrs{Idx} = X ;
Put A1= / A2= / A3= /A4= /A5=;
Run ;