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 (March 2012, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 22 Mar 2012 13:03:28 +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: Extract only numeric values from an alphanumeric column
Comments: To: darth.pathos@gmail.com
In-Reply-To:  <CAAEgM6k0Xy6-MEROMKU0V3_mASecW==_g+E=5C2GEv6U5moJMg@mail.gmail.com>
Content-Type: text/plain; charset="Windows-1252"

?? is a designed hack to suppress the error message and the _error_ from being set to 1 that will be issued when the Input function tries to convert a character value.... In short some shops will accept its use and others like mine wont. ^missing = not missing.... the ^ means 'not'

Toby Dunn

If you get thrown from a horse, you have to get up and get back on, unless you landed on a cactus; then you have to roll around and scream in pain. “Any idiot can face a crisis—it’s day to day living that wears you out” ~ Anton Chekhov

> Date: Thu, 22 Mar 2012 08:59:03 -0400 > From: darth.pathos@GMAIL.COM > Subject: Re: Extract only numeric values from an alphanumeric column > To: SAS-L@LISTSERV.UGA.EDU > > Hi Mike, > > Thanks so much, that works perfectly!! > > Could you explain the purpose of the "??" and the "^missing"? I've never > seen those and always like to have as complete an understanding as possible. > > Thanks again for your time > Chris > > On Thu, Mar 22, 2012 at 8:43 AM, Zdeb, Michael S <mzdeb@albany.edu> wrote: > > > hi ... 1.0 is valid numeric data bit would get flagged by NONDIGIT because > > of the decimal point > > (as is 1e3, etc. and other forms of numbers acceptable to SAS) > > > > data x; > > input result : $10. @@; > > datalines; > > 1.0 32 >1000 NEG . 123 1e3 > > ; > > > > data _null_; > > set x; > > if notdigit(strip(result)) then put result=; > > run; > > > > LOG ... > > result=1.0 > > result=>1000 > > result=NEG > > result=1e3 > > > > so how about ... > > > > data y; > > set x; > > num = input(result, ?? 10.); > > if ^missing(num); > > drop result; > > run; > > > > and if commas are OK (also flagged by NONDIGIT) ... > > > > data x; > > input result : $10. @@; > > datalines; > > 1.0 32 >1000 NEG . 123 1e3 2,000 > > ; > > > > data y; > > set x; > > num = input(result, ?? comma10.); > > if ^missing(num); > > drop result; > > run; > > > > > > > > Mike Zdeb > > U@Albany School of Public Health > > One University Place (Room 119) > > Rensselaer, New York 12144-3456 > > P/518-402-6479 F/630-604-1475 > > > > ________________________________________ > > From: SAS(r) Discussion [SAS-L@LISTSERV.UGA.EDU] on behalf of Christopher > > Battiston [darth.pathos@GMAIL.COM] > > Sent: Thursday, March 22, 2012 8:06 AM > > To: SAS-L@LISTSERV.UGA.EDU > > Subject: Extract only numeric values from an alphanumeric column > > > > Hi all, > > > > I have a Labs result table where the "Results" column has all sorts of data > > (POS, <3, 1+, etc.). I would like to somehow extract only the numeric data > > so I can graph the results but I'm not entirely sure how. I was hoping > > that I could use if the first character was a number or a decimal, but that > > doesn't work because I have results like the 1+ in the examples, and then > > others like .3a (which I believe is a typo but data quality is a challenge > > left for another day). > > > > I could use PROC SQL to do a "NOT LIKE '%a%" for all the letters and > > characters but that is just ridiculous. I went to Cody's Data Cleaning > > Techniques (rapidly becoming one of my most used books in my SAS > > collection) and found the NOTDIGIT function. > > > > I created a table in WORK using PROC SQL (I want only this year's data) and > > had set my DATA step as > > > > data _null_; > > set work.lab; > > file print; > > if notdigit(trim(result)) and not missing(result) > > then put result= result_date=; > > run; > > > > The problem is that it returns what appears to be my complete dataset (1.0, > > 32, >1000, NEG, etc. etc.). So, what am I missing? What I'm thinking is > > creating a data set with the results from the DATA step, and then delete > > those results from WORK.LAB. > > > > Any suggestions would be appreciated. > > Chris > >


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