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
|