Date: Tue, 4 May 1999 13:04:29 +0100
Reply-To: Peter Crawford <Peter@CRAWFORDSOFTWARE.DEMON.CO.UK>
Sender: "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From: Peter Crawford <Peter@CRAWFORDSOFTWARE.DEMON.CO.UK>
Organization: Crawford Software Consultancy Limited
Subject: Re: Scan function question
Deborah B Buck <103525.2762@COMPUSERVE.COM> writes
> I'm a little hesitant about asking this question in this forum - with
>all the gurus, mavens, etc., but I can't seem to find the answer
>in the SAS manuals.
> I have a file that I've read into a SAS dataset and I'm trying to use
>the scan function to help me separate information within a variable.
>The data has been entered so that a pair of symbols is necessary
>to tell where the divider exists. (For example, 2 commas or
>a comma and a pound sign.)
> If I try to do something like-
> The resulting x occurs whenever a comma OR pound sign is
>present - which is what the function is supposed to do. Is there
>a simple way to tell SAS that both must occur together?
> Thanks in advance - You all are a gold-mine of info, even for
>a long-time SAS user like me. (Of course, I started programming
>in SAS at a very young age!)
> Debbie Buck
There is the indexw() function, but it expects blank delimiters
You may have to use index( y, ',#' ) to locate the delimiter and
substr() to pull out the target...
pos1 = index( y, ',#' ); /* find first delim */
str1 = substr( y, pos1 +2 ); /* take all text from after delim */
pos1 = index( str1, ',#' ); /* find position of next delim */
x = substr( str1, 1, pos1 -1 ); /* trim off from next delim */
You should also take care where these delim may be absent (string end).
Peter Crawford (_knowledge_ is a poor substitute for *real* experience,
but they make a great team)