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 (March 1998, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Tue, 17 Mar 1998 08:54:46 -0800
Reply-To:     Dale McLerran <dmclerra@FHCRC.ORG>
Sender:       "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From:         Dale McLerran <dmclerra@FHCRC.ORG>
Organization: Fred Hutchinson Cancer Research Center
Subject:      Re: space in macro text
Content-Type: text/plain; charset=us-ascii

No_body wrote: > > Hi, everyone, > > I have a macro variable that holds a string like 'a1 b1 c1 dd1 > eee1', the spaces between text varies, and so are the text which are less > than 8 digits, how do I made the the length of text plus following spaces > equal to 9 (i.e., 'a1 b1 c1 dd1 eee1 ')? Any > suggestion would be greatly appreciated. Please CC my e-mail when replying > to group. > > TIA. > > YZ

YZ,

The following should work:

%macro expand; %let oldstrng=a1 b1 c1 dd1 eee1; %let newstrng=; %let space=%str( ); %let nwords=0; %do i=1 %to %length(&oldstrng); %let currword=%scan(&oldstrng,&i); %if &currword=%str() %then %goto out_i; %let nwords=%eval(&nwords + 1); %let newstrng=&newstrng.&currword; %let lng_curr=%length(&currword); %do j=1 %to %eval(9 - &lng_curr); %let newstrng=&newstrng.&space; %end; %end;

%out_i: %put oldstrng=&oldstrng; %put newstrng=&newstrng; %mend;

However, I have to ask why you need the words spaced this way. If you simply want to return the i-th "word", the scan function will do. The above code will also return the number of words in your string. Is there some good reason for keeping the words in the string equally spaced?

Dale _

Dale McLerran dmclerra@fhcrc.org Fred Hutchinson Cancer Research Center ph: (206) 667-2926 1124 Columbia Street fax: (206) 667-5977 Seattle, WA 98104


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