Date: Thu, 6 Nov 2008 14:46:39 -0800
Reply-To: "Schwarz, Barry A" <barry.a.schwarz@BOEING.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Schwarz, Barry A" <barry.a.schwarz@BOEING.COM>
Subject: Re: String tokenizer
In-Reply-To: <200811061952.mA6BkIfW002005@malibu.cc.uga.edu>
Content-Type: text/plain; charset="us-ascii"
You could save (and test) the results of the SCAN function before
calling SYMPUT. Something like
Data _null_;
do i=1 by 1
save = scan("&instring",i,',');
if save = ' ' then leave;
call symput(cats('var',i),save));
end;
call symput(max_i,i);
put _all_ '=';
Run;
%do i = 1 %to &max_i;
%put &&var&i;
%end;
-----Original Message-----
From: Jerry Yang
Sent: Thursday, November 06, 2008 11:52 AM
To: SAS-L@LISTSERV.UGA.EDU
Subject: Re: String tokenizer
Thanks everyone for the solution!
My issue now is trying to make it dynamic.
Since this tool allows the user to enter multiple strings, I cannot know
exactly how many strings and var# i would have.
Is there a way to check for the end of string?
-Jerry
On Thu, 6 Nov 2008 10:29:20 -0800, Akshaya wrote:
>A solution using Data step:
>
>%let instring=Package-A, Package-B, Box-1, Box-2;
>
>Data _null_;
> do i=1 to 4;
> call symput(cats('var',i),scan("&instring",i,','));
> end;
> put _all_ '=';
>Run;
>
>%put &var1 &var2 &var3 &var4;
>
>Akshaya
|