Date: Sun, 13 Feb 2005 17:35:29 +1100
Reply-To: Scott <usenet739_yahoo_com_au@CRONKITE.CC.UGA.EDU>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Scott <usenet739_yahoo_com_au@CRONKITE.CC.UGA.EDU>
Subject: Re: changing var from num to char.
Hi Nishant,
You have a number of errors here, which I'll point out to help your
understanding of SAS:
data _null_:
is a null or "throwaway" dataset - you aren't saving your processing
array a[12]:
arrays loop over variables, not observations. and you haven't assigned
your array to any variables
do i=1 to nobs:
you're capturing the number of observations into nobs, but then using
that as your index into the array. IOW you're mixing observation count and
array indices. not what you would want to do.
you've got your set statement inside a loop - each time the set statement is
encountered, SAS will read the next observation from your dataset.
your last data step has no input - no set statement.
what you probably want to do is:
data analysis.ecg; /* save your output, overwriting your input (use a
different name if desired) */
length patient $9; /* define the patient variable */
set analysis.ecg (rename=(patient=oldpt)); /* rename the input var into
a temp var */
patient=put(oldpt,$9.); /* use a format to do num2char conversion */
drop oldpt; /* drop the temp var */
run;
Hope this helps,
Scott
"Nishant Dholakia" <nishant.dholakia@GMAIL.COM> wrote in message
news:200502130232.j1D2WMgo023608@listserv.cc.uga.edu...
> 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