Date: Thu, 14 May 2009 09:14:39 -0700
Reply-To: "Choate, Paul@DDS" <pchoate@DDS.CA.GOV>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Choate, Paul@DDS" <pchoate@DDS.CA.GOV>
Subject: Re: Looking for a macro or code to convert char to numeric while
retaining order.
In-Reply-To: A<4A0C2B9E.40303@neuro.uu.se>
Content-Type: text/plain; charset="iso-8859-1"
Thomas -
To add a little to Joe's excellent suggestion:
Enter the 25 variable names into the rename and input lines below and change the YOURFILE references.
proc contents data=YOURFILE out=varlist(keep=name varnum) noprint; run;
proc sql;
select name into :namelist separated by ' ' from varlist order by varnum;
quit;
data YOURFILE(drop=_:);
retain &namelist;
set YOURFILE(rename=(n1=_n1
n2=_n2));
n1=input(_n1,best12.);
n2=input(_n2,best12.);
run;
One thing for you to think about - it's usually simpler to read the data correctly in the first place - if this is imported somehow there are usually ways to instruct the program to read the data correctly and avoid this problem.
Hope that helps -
Paul Choate
DDS Data Extraction
(916) 654-2160
-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of Thomas Fröjd
Sent: Thursday, May 14, 2009 7:33 AM
To: SAS-L@LISTSERV.UGA.EDU
Subject: Re: Looking for a macro or code to convert char to numeric while retaining order.
Only 25 of about 150 variables should be converted. Theese are variables
that contain numbers between 0 and 9 usually. I dont want to convert all
character variables since i have some that contains text.
Gerhard Hellriegel skrev:
> depends on some further information: should ALL character variables been
> converted? Are they all standard numerics or something like time,
> date, ...? Should the names be the same or changed?
> A few informations would be nice.
> Gerhard
>
>
>
>
> On Thu, 14 May 2009 11:26:04 +0200, =?ISO-8859-1?Q?Thomas_Fr=F6jd?=
> <thomas.frojd@NEURO.UU.SE> wrote:
>
>
>> Hi, I have a large data set where about 20 variables have been
>> mistankenly read in as character variables. I would like to convert them
>> to numeric while still retaining the old order of the variables. Anyone
>> have some code I can use for this? I figure it should be a quite common
>> problem.
>>
>> Best regards!
>>