Date: Thu, 6 Nov 2008 12:06:02 -0600
Reply-To: Joe Matise <snoopy369@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Joe Matise <snoopy369@GMAIL.COM>
Subject: Re: String tokenizer
In-Reply-To: <941871A13165C2418EC144ACB212BDB0BEB213@dshsmxoly1504g.dshs.wa.lcl>
Content-Type: text/plain; charset=ISO-8859-1
If it does contain quotes, don't forget about %unquote( )
-Joe
On Thu, Nov 6, 2008 at 11:57 AM, Nordlund, Dan (DSHS/RDA) <
NordlDJ@dshs.wa.gov> wrote:
> > -----Original Message-----
> > From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On
> > Behalf Of Jerry Yang
> > Sent: Thursday, November 06, 2008 9:37 AM
> > To: SAS-L@LISTSERV.UGA.EDU
> > Subject: String tokenizer
> >
> > Hi,
> >
> > So I am reading in a string from a front end (our Stored
> > Process in EG) and
> > one of the macro variables will contain a string in the
> > following format:
> > "Package-A, Package-B, Box-1, Box-2".
> >
> > I want to be able to tokenize the string and put them in
> > separate macro
> > variables.
> > Ie.
> >
> > &var1=Package-A
> > &var2=Package-A
> > &var3=Box-1
> > &var4=Box-2
> >
> >
> > Is there a simple function that can do that? Or do i need to use a
> > combination of functions?
> >
> > Any help is appreciated. Thanks!
> >
>
> Jerry,
>
> There are lots of ways this could be done, depending on whether macro
> variables var1-var4 should be local or global. Also, does the macro
> variable with the string "Package-A, Package-B, Box-1, Box-2" actually
> contain the quotes? For a global variable solution, it could be as simple
> as
>
> %let instring=Package-A, Package-B, Box-1, Box-2;
>
>
> %macro tokens(v1,v2,v3,v4);
> %global var1 var2 var3 var4;
> %let var1=&v1;
> %let var2=&v2;
> %let var3=&v3;
> %let var4=&v4;
> %mend;
>
> %tokens(&instring)
>
> If this doesn't do what you want, if you provide some more detail about
> what you are doing, someone will surely be able to helpf out.
>
> Hope this is helpful,
>
> Dan
>
> Daniel J. Nordlund
> Washington State Department of Social and Health Services
> Planning, Performance, and Accountability
> Research and Data Analysis Division
> Olympia, WA 98504-5204
>
|