LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (December 2010, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Sun, 26 Dec 2010 18:29:22 +0000
Reply-To:     toby dunn <tobydunn@HOTMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         toby dunn <tobydunn@HOTMAIL.COM>
Subject:      Re: Is there an easier way to solve this?
Comments: To: art297@rogers.com
In-Reply-To:  <201012261759.oBQBlfmA030605@wasabi.cc.uga.edu>
Content-Type: text/plain; charset="iso-8859-1"

Untested: Data Address ( Drop = Text Pattern Match ) ; Length City $ 40 State $ 2 Zip $ 5 Address $ 20 FirstName LastName $ 20 ;

Infile Cards ; Input FirstName $ LastName $ / Address $ / Text $ ;

Pattern = ( '/^(.*)\s+([A-Z]{2})\s+(\d{5})$/o' ) ; Match = ( Pattern , Strip( Text ) ) ; City = PrxPosn( Pattern , 1 , Text ) ; State = PrxPosn( Pattern , 2 , Text ) ; Zip = PrxPosn( Pattern , 3 , Text ) ; Cards ; Lee Athnos 1215 Raintree Circle New York NY 85044 Heidie Baker 1751 Diehl Road Vienna VA 22124 ;

Run ; If you want to expand the pattern to make things optional or to encopass the possibility of the extended ZipCodes you can just jack with the pattern a little. Toby Dunn

"I'm a hell bent 100% Texan til I die"

"Don't touch my Willie, I don't know you that well"

> Date: Sun, 26 Dec 2010 12:59:24 -0500 > From: art297@ROGERS.COM > Subject: Re: Is there an easier way to solve this? > To: SAS-L@LISTSERV.UGA.EDU > > Jack, > > Nice try but no cigar! The problem, in this case, is how to get SAS to read > from right to left, ONLY allowing embedded space in the left most field. > > Art > ------- > On Sun, 26 Dec 2010 09:41:01 -0800, Jack Hamilton <jfh@STANFORDALUMNI.ORG> > wrote: > > >I don't have SAS on this machine, so I can't try it, but what about > > > >> input FirstName $ LastName $ / > >> Address $ 1 - 20 / > >> city $ @' ' state $ @' ' zip $; > > > > > >> > > > > > >On Dec 26, 2010, at 9:07 AM, Nat Wooding wrote: > > > >> Art > >> > >> I have approached this type of problem in a similar fashion in past. > >> Sometimes I don't bother with a new variable (_third_line) but simply use > >> _infile_. Just for grins, here is a slightly different way to extract the > >> city. > >> > >> Nat > >> > >> > >> data work.Address (drop=_:); > >> infile cards; > >> input FirstName $ LastName $ / > >> Address $ 1 - 20 / > >> _Third_Line & $80.; > >> LENGTH City $ 40 state $ 2 zip $5 ; > >> Zip=scan(_Third_Line,-1); > >> State=scan(_Third_Line,-2); > >> > >> > >> City=substr(_Third_Line,1,LENGTH( CATX(' ', ZIP, STATE)) + 1); > >> cards; > >> Lee Athnos > >> 1215 Raintree Circle > >> New York NY 85044 > >> Heidie Baker > >> 1751 Diehl Road > >> Vienna VA 22124 > >> ; > >> > >> > >> -----Original Message----- > >> From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of > Arthur > >> Tabachneck > >> Sent: Sunday, December 26, 2010 11:07 AM > >> To: SAS-L@LISTSERV.UGA.EDU > >> Subject: Is there an easier way to solve this? > >> > >> The following was a question that was raised on the SAS discussion forum. > >> You are confronted with data that has 3 lines per subject, but the third > >> line has variables that may contain embedded spaces, but there is only > one > >> space between variables. > >> > >> The only suggestion I could think of was the one shown below. Is there > an > >> easier way? > >> > >> data work.Address (drop=_:); > >> infile cards; > >> input FirstName $ LastName $ / > >> Address $ 1 - 20 / > >> _Third_Line & $80.; > >> format City $10.; > >> Zip=scan(_Third_Line,-1); > >> State=scan(_Third_Line,-2); > >> call scan(_Third_Line, -2, _position, _length); > >> City=substr(_Third_Line,1,_position-1); > >> cards; > >> Lee Athnos > >> 1215 Raintree Circle > >> New York NY 85044 > >> Heidie Baker > >> 1751 Diehl Road > >> Vienna VA 22124 > >> ; > >> > >> Thanks in advance, > >> Art


Back to: Top of message | Previous page | Main SAS-L page