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 (April 2001, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 12 Apr 2001 13:29:23 -0700
Reply-To:     "Huang, Ya" <ya.huang@AGOURON.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         "Huang, Ya" <ya.huang@AGOURON.COM>
Subject:      Re: converting ALL data from Character to Numeric
Comments: To: Jim Agnew <Agnew@HSC.VCU.EDU>
Content-Type: multipart/alternative;

Hi Jim and Cren,

Similar question was raised a few months ago, I provided my solution then. Let me re-post here today.

Assumption: Your character variable only include pure number, NO comma, BUT it can be a scientific notion like 1.02e3.

data xx; input n1 a $ b $; label a='label a' b='label b'; cards; 1 23 -45 2 1.02e3 36.09 56 2,000.3 +8 ;

proc sql noprint; select "input("||compress(name)||",best10.) as "||compress(name) ||" label='"||trim(label)||"'" into : charlist separated by "," from dictionary.columns where libname='WORK' and memname='XX' and type='char' ; select name into : numlist separated by ',' from dictionary.columns where libname='WORK' and memname='XX' and type='num' ; create table xx as select &numlist , &charlist from xx ;

options nocenter; proc contents;

proc print label; run; ---------------------

-----Alphabetic List of Variables and Attributes-----

# Variable Type Len Pos Label ------------------------------------------------- 2 a Num 8 8 label a 3 b Num 8 16 label b 1 n1 Num 8 0

label label Obs n1 a b

1 1 23 -45.00 2 2 1020 36.09 3 56 . 8.00

Note in obs 3, there is a missing, it was caused by a comma formatted number. The above code keep the data set name unchanged, variable name unchanged, while all character variable changed to numeric.

HTH

Ya Huang

-----Original Message----- From: Jim Agnew [mailto:Agnew@HSC.VCU.EDU] Sent: Thursday, April 12, 2001 11:47 AM To: SAS-L@LISTSERV.UGA.EDU Subject: converting ALL data from Character to Numeric

Dear kind fellows....

We have been handed this large database by a company to analyze, however it's in character format only. We'd like to convert the "numeric data" to numeric from character format where it's stored presently.

Other than by hand-coding each and every single variable, is there a way to wholesale convert it all?

Thanks, and we will summarize.

Jim and Cren


[text/html]


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