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 (February 2005, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Mon, 14 Feb 2005 18:07:40 -0500
Reply-To:     Sigurd Hermansen <HERMANS1@WESTAT.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Sigurd Hermansen <HERMANS1@WESTAT.COM>
Subject:      Re: changing var from num to char.
Content-Type: text/plain

Some situations may call for conversions of column values in a dataset from one type to another. Generally I would prefer to use a view to create a column of character values on the fly:

create view newVW as select put(nDat,1.) as cDat,* from .... ;

The view provides the character variable as needed. Sig

-----Original Message----- From: Sigurd Hermansen Sent: Monday, February 14, 2005 4:04 PM To: SAS-L@LISTSERV.UGA.EDU Subject: Re: changing var from num to char.

Nishant: Typical SAS Data steps and SAS SQL both loop automatically through a dataset. Neither a program nor a query can replace columns in dataset or change numeric type columns to character, or the other way around.

Just as it takes three assignments to interchange values of two variables, it takes three operations to convert a column from numeric to character type. This example shows how that process works in SAS SQL:

data test; ndat=5; run; proc sql; alter table test add cdat char(1) ; update test set cdat=put(ndat,1.) ; alter table test drop ndat ; quit; proc print data=test; run;

This sequence of queries consists of two operations on data structure and an update in situ. Data step solutions usually require reading a dataset and writing a new dataset (even if the second has the same name as the first). Sig

-----Original Message----- From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of Nishant Dholakia Sent: Saturday, February 12, 2005 9:32 PM To: SAS-L@LISTSERV.UGA.EDU Subject: changing var from num to char.

hi all, there has been some postings regarding this matter and i tried to create a code that converts a particular numeric column into rows.

/* for conversion of patient variable from numeric to char in patient1*/ data _null_; array a[12]; do i =1 to nobs; set analysis.ecg nobs= nobs; a[i] = put(patient, $9.); put a[i]; patient1 = a[i]; end; run;

/*dropping the column patient*/

proc sql; alter table analysis.ecg drop patient; quit;

/*renaming patient1 to patient*/

data analysis.ecg(rename = (patient1 = patient); run;

ideally I feel this is a logical way to convert a column from numeric to character however I am getting errors please tell me if there is a mistake in teh logic thanks in advance


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