LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (September 2000, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 28 Sep 2000 08:43:10 -0400
Reply-To:     Howard Schreier <Howard_Schreier@ITA.DOC.GOV>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Howard Schreier <Howard_Schreier@ITA.DOC.GOV>
Subject:      Re: WHAT IS WRONG WITH THIS CODE?

Here's one way of doing this which makes use of a lot of built-in SAS capabilities to handle most of the messy details.

I've changed the initial length from 86 to 40 and the target length from 40 to 12 in order to make things more compact.

There is an intermediate file which, for convenience, I am holding in a catalog entry (though the method would work just as well with an external file).

filename twelve catalog 'work.data.temp12' lrecl=12;

First, read in the given data, use the SCAN function to extract individual words, and write to the intermediate file:

data _null_; INPUT topic:& $char40. id $; file twelve; put @2 id; length word $ 40; do index= 1 by 1 until (word=''); word = scan(topic,index,' '); put word @; end; put; cards; This is some text to be wrapped. obj1 Intitial line length is 40 characters. obj1 Target length is 12. obj1 But the method can be generalized. obj1 Most words will be short enough to fit. obj2 But not_always,_so_let's_see_what we get obj2 ;

Now load the wrapped strings into a SAS data set. The ID values were indented by one space, so they can be distinguished from the content.

data twelve; infile twelve truncover; input col1 $ 1 @; if col1=' ' then do; input id $; retain id; recnum + 1; end; else do; input twelve $ 1-12; output; end; run;

Now let PROC TRANSPOSE put the related strings together, in observations which will correspond one-to-one with the original data lines.

proc transpose data=twelve out=all(drop = recnum _name_); by recnum id; var twelve; run;

Result:

ID COL1 COL2 COL3 COL4

obj1 This is some text to be wrapped. obj1 Intitial line length is 40 characters. obj1 Target length is 12. obj1 But the method can be generalized. obj2 Most words will be short enough to fit. obj2 But not_always,_ so_let's_see _what we get

Notice that the long run-on word was chopped into pieces, which is probably the preferred behavior. But there was no need to develop explicit DATA step code to do this.

On Tue, 26 Sep 2000 08:42:04 -0600, Jamil Ibrahim <jibrahim@IR.UMSMED.EDU> wrote:

>Hi my goal is to make this code wrap the var topic into 40 character lines >.......... > [snip] >> Jamil Ibrahim wrote [in part]: >> > DATA srf1 ; >> > >> > INPUT @1 topic $char86. @88 id $char4.; >> > >> > Len = length ( TOPIC ) ; >> > >> > do while(length( len) gt 0) ; q+1; >> > >> > rev = reverse ( substr(TOPIC,1,40) ) ; >> > x = index ( rev , " " ) ; >> > L1= left(reverse(substr(rev,x+1))) ; >> > topic = left(substr ( TOPIC , 40 - x + 1)) ; [snip] >> > >> > len=length (topic); output; return; >> > end; return; >> > datalines; >> > a. Describe preparation and aesthetic pointers for porcelain laminate >> veneers- 1991. obj1 >> > b. Describe preparation and aesthetic pointers for porcelain laminate >> veneers- 1991. obj1 >> > c. Describe preparation and aesthetic pointers for porcelain laminate >> veneers- 1994. obj1 >> > d. Describe preparation and aesthetic pointers for porcelain laminate >> veneers- 1994. obj1 >> > e. Describe methods for reattachment of dislodged crowns/bridges to >> abutments- 1998. obj2 >> > f. Describe methods for reattachment of dislodged crowns/bridges to >> abutments- 2000. obj2 >> > ;


Back to: Top of message | Previous page | Main SAS-L page