LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous (more recent) messageNext (less recent) messagePrevious (more recent) in topicNext (less recent) in topicPrevious (more recent) by same authorNext (less recent) by same authorPrevious page (June 2009, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Fri, 26 Jun 2009 12:13:15 -0500
Reply-To:   Joe Matise <snoopy369@GMAIL.COM>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   Joe Matise <snoopy369@GMAIL.COM>
Subject:   Re: Character to numeric
Comments:   To: Michael Bryce Herrington <mherrin@g.clemson.edu>
In-Reply-To:   <e52cf8710906260955r36b06262g792ddda048d1f138@mail.gmail.com>
Content-Type:   text/plain; charset=ISO-8859-1

If it weren't for ?,* i'd say use special missing values on input (input A,B,C,...,X as .A, .B, .C. ... .X ) ... you could convert * and ? to Y and Z I suppose, and still do it that way ...

-Joe

On Fri, Jun 26, 2009 at 11:55 AM, Michael Bryce Herrington < mherrin@g.clemson.edu> wrote:

> Thanks to all. I got one to do what I needed. Thanks for all the > different > techniques as well. > > On Fri, Jun 26, 2009 at 12:17 PM, mata <mvitvit@yahoo.com> wrote: > > > Hey, > > > > Regexp could be another solution: > > > > Mata > > > > data sample; > > input finishpos1 $3. finishpos2 $3. ; > > datalines; > > 1 5 > > 4 2 > > 6 4 > > 3 3 > > 8 A > > 9 5 > > 4 F > > N 9 > > 10 7 > > ; > > > > data final; > > set sample; > > > > array t0(*) $3. finishpos1 finishpos2; > > array tn(*) finishpos1n finishpos2n; > > array tc(*) $3. finishpos1c finishpos2c; > > > > do i=1 to dim(t0); > > if prxmatch('/\d/',t0(i))=0 then tc(i)=t0(i); > > else tn(i)=input(t0(i),2.); > > end; > > drop i; > > run; > > > > proc print data=final; run; > > > > > > On Jun 26, 7:48 am, mher...@G.CLEMSON.EDU (Michael Bryce Herrington) > > wrote: > > > Hey, > > > > > > I have a variable that contains numerical and character values, > 1,2,3,... > > > A,B,C,...,X,?,*. The character values represent lets say > 'circumstancial > > > excuses' and occur far less often than the numerical values. I have > > created > > > a new variable for the character values to save them, and replaced them > > in > > > this variable as missing values. Now I would like to format the > > > original variable into a numeric variable. I am mainly trying to avoid > > the > > > character to numeric note in the log to make sure there are no errors > > being > > > performed in the data. Thanks for your help. > > > > > > I have added a small sample and a sample of the code which I am trying > to > > > perform. > > > > > > * > > > > > > data* sample; > > > > > > input finishpos1 $3. finishpos2 $3. ; > > > > > > datalines; > > > > > > 1 5 > > > > > > 4 2 > > > > > > 6 4 > > > > > > 3 3 > > > > > > 8 A > > > > > > 9 5 > > > > > > 4 F > > > > > > N 9 > > > > > > 10 7 > > > > > > ; > > > * > > > > > > run*; > > > * > > > > > > data* sample; > > > > > > set sample; > > > > > > *new variable to keep the character values; > > > > > > if finishpos1 > > in('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O' > > > ,'P','Q','R','S','T','U','V','W','X','Y','?','*','\') > > > thenfinishposDNF1=finishpos1; > > > > > > else finishposDNF1=''; > > > > > > *replace character values with missing values in original variable; > > > > > > if finishpos1 > > in('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O' > > > ,'P','Q','R','S','T','U','V','W','X','Y','?','*','\') then > > finishpos1=*.*; > > > > > > * attempt to reformat the original variable to numeric; > > > > > > *THIS IS WHERE i NEED HELP; > > > > > > finishpos1=input(finishpos1,*2.*); > > > > > > *repeat for finishpos2, finishpos3, etc... (only two in the sample); > > > > > > if finishpos2 > > in('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O' > > > ,'P','Q','R','S','T','U','V','W','X','Y','?','*','\') > > > thenfinishposDNF2=finishpos2; > > > > > > else finishposDNF2=''; > > > > > > if finishpos2 > > in('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O' > > > ,'P','Q','R','S','T','U','V','W','X','Y','?','*','\') then > > finishpos2=*.*; > > > > > > finishpos2=input(finishpos2,*2.*); > > > * > > > > > > run*; > > > > > > -- > > > Bryce Herrington > > > Clemson University > > > mher...@g.clemson.edu > > > (863) 258-4758 > > > > > > -- > Bryce Herrington > Clemson University > mherrin@g.clemson.edu > (863) 258-4758 >


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