| Date: | Tue, 5 Dec 2000 11:04:21 -0500 |
| Reply-To: | "Fehd, Ronald J." <rjf2@CDC.GOV> |
| Sender: | "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU> |
| From: | "Fehd, Ronald J." <rjf2@CDC.GOV> |
| Subject: | Re: Scan or substr or tranwrd |
|
| Content-Type: | text/plain; charset="iso-8859-1" |
|---|
> From: Schulthess, Rebecca [mailto:schulthr@MMRF.MFLDCLIN.EDU]
> I have a file that has a variable, CSZ3, which contains the
> city, state and
> zip. Example: Marshfield WI 54449 (space delimited). I am using the
> following code to extract the separate parts
> city=scan(csz3,1,''); The
> problem I have is when the city name is more than one word.
> For example ST
> GERMAINE WI 54558. All I get is the ST. Does anyone know
> how I can get
> both parts of the city name? (The length of the city name
> changes with each different city).
oh, definitely a question for the SAS-L Whizards!
you can approach this from either side
trying to figure when you have a two-word city
or just whack off the state and zip.
city = scan(csz3,1,' ');
state = scan(csz3,2,' ');
zip = scan(csz3,3,' ');
you'll remember from recent threads that scan can take a negative position
argument
so
zip = scan(csz3,-1,' ');
and
state = scan(csz3,-2,' ');
now that we have the state, we'll whack from position one up to state:
City = substr(csz3,1,index(csz3,State));%* you may want to trim() State;
alternatly you could use tranword(sp) function:
City = tranwrd(csz3,trim(zip) ,' ');
City = tranwrd(csz3,trim(State),' ');
for the case, perhaps decidely remote,
where your city name contains the state abbreviation:
City = tranwrd(csz3,' ' !! trim(State) !! ' ',' ');
hth
Ron Fehd the string-handling maven CDC Atlanta GA USA RJF2@cdc.gov
OpSys: WinNT Ver: 8.1
---> cheerful provider of UNTESTED SAS code!*! <---
archives: http://www.listserv.uga.edu/archives/sas-l.html
By using your intelligence you can sometimes make your problems twice as
complicated.
-- Ashleigh Brilliant
|