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 (June 2005, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Fri, 3 Jun 2005 12:22:17 -0400
Reply-To:     Venky Chakravarthy <swovcc@HOTMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Venky Chakravarthy <swovcc@HOTMAIL.COM>
Subject:      Re: using Perl regex to validate values in SAS 9.1
Comments: To: rune@FASTLANE.NO
Content-Type: text/plain; charset=ISO-8859-1

What are the rules for Van Husen, Jeff who has both Phone1 and Phone2 missing?

On Fri, 3 Jun 2005 15:40:21 +0200, Rune RunnestÝ <rune@FASTLANE.NO> wrote:

>Yet another small justification of the conditions. >The criteria for the records in the dataset WRONGRECORDS is that there shall >be one or more non-numbers in one or both of the columns phone1 and phone2. >The code seems to work OK with one exception: The record with Mary O'Reily >should not be in WRONGRECORDS. Because blank values are allowed (phone1). I >*suppose* it has come here because of the blank value in phone1. > > >data staff; > attrib name length=$20 > phone1 length=$12 > phone2 length=$12; > infile cards; > input @1 name $20. > @21 phone1 $12. > @34 phone2 $12.; >datalines; >O'Reily, Mary 123456789888 >Pyles, Jane 2B3667567715 987654328887 >Hoffman, Valerie 2C268660808 234234234234 >Dawn, Jennifer 718638361549 5B7898765476 >Van Husen, Jeff >Sim-Smith, Angela 201681265665 5C9876567865 >Timmons, David 5866806 34543234 >Benjamin, Catherine 203678161777 234567432334 >Windsor, Stephen 718638462849 876422345564 >Richardson, Larry 718638468816 556768432234 >Bellum, Sarah 2066756434 3454799665 >Garcia Tracy 21268761247 348564332 >Montgomery, Adam 212658763622 789023456677 >George, Clara 203678161212 345656667777 >Sabatini, Anthony 203678160019 3E5678932RT5 >; >run; > >data wrongrecords; > set staff; > where not missing(phone1) or not missing(phone2); /* we want to push >away > the records where *both* phone1 and phone2 are blank. > If we had used 'and' instead of 'or', we would wrongly > pushed away Mary O'Reily too. */ > *alternatively, we could have used this sentence:; > *where phone1 ne "" or phone2 ne ""; > if _n_ = 1 then > do; > retain re; > re = prxparse('/[^\d]/'); /* match only non-numbers*/ > if missing(re) then > do; > putlog 'ERROR: malformed regex'; > stop; > end; > end; > if prxmatch(re,trim(phone1)) or prxmatch(re,trim(phone2)); >run; > > >Regards >Rune


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