Date: Tue, 30 Nov 1999 16:48:35 -0500
Reply-To: S David Riba <dave@JADETEK.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: S David Riba <dave@JADETEK.COM>
Subject: Re: alpha numeric variable question
Content-Type: text/plain; charset="iso-8859-1"
Try the following:
city = substr(name,1,index(name,',') -5 ) ;
state = substr(name,index(name,',') +2 ) ;
This yields:
NAME=NEW YORK CITY CITY, NY
CITY=NEW YORK CITY
STATE=NY
NAME=RICHMOND CITY, CA
CITY=RICHMOND
STATE=CA
The INDEX function determines the position of a character in the string. I
used the comma as the most typical delimiter. Normally you would back off
one position. However, since your text uses the word CITY, I backed off
five positions to derive the CITY value. Alternatively, you could have used
the string 'CITY,' with an index increment of -1.
HTH
Dave
----------------------------------------------------------------------------
S. David Riba INTERNET: dave@JADETEK.COM
JADE Tech, Inc. http://www.jadetek.com
P O Box 4517
Clearwater, FL 33758 SAS Certified Professional - V6
VOICE: (727) 726-6099 A SAS Institute Quality Partner
SAS. It's not just an attitude
----- Original Message -----
From: Denis Marchand <denis@PHYRES.LAN.MCGILL.CA>
Newsgroups: bit.listserv.sas-l
To: <SAS-L@LISTSERV.UGA.EDU>
Sent: Tuesday, November 30, 1999 3:38 PM
Subject: alpha numeric variable question
> Hi SAS experts!
>
> Can anyone push me in the right direction on this one.
>
> I am reading in an ASCII file that contains a city variable. This
> field always finishes by CITY, XX
> file 1
> ex: NEW YORK CITY CITY, NY
> RICHMOND CITY, CA
> etc.
>
>
> I need this city field to merge with another file that contains also
> a city variable which contains an abreviated city name.
> file 2
> ex: NEW YORK CITY
> RICHMOND
>
> My approach would be to find a way to read in the file 1 city
> variable and get rid of the CITY, XX part.
>
> Is there a way to do this or is there an easier approach?
>
> Any insight would be of great help..
>
> Thanks
>
> Denis
>
>
> *************************************************
> Denis Marchand
> Analyste de Planification/Planning Analyst
> Bureau de Planification de l'Universite McGill
> McGill University Planning Office
> tel:(514)398-7141
> telecopie/facsimile:(514)398-7358
> Denis@phyres.lan.mcgill.ca
> *************************************************
|