Date: Fri, 2 Oct 2009 18:43:20 -0400
Reply-To: Arthur Tabachneck <art297@NETSCAPE.NET>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Arthur Tabachneck <art297@NETSCAPE.NET>
Subject: Re: how to convert a num. item to char in proc sql?
In your original post you didn't indicate that you were working with
Try the following:
create table have_char as
select left(put(oldvalue,8.4)) as newvalue
PROC EXPORT DATA= WORK.have_char
I end up with a spreadsheet that looks like:
Is that what you want your file to look like?
On Fri, 2 Oct 2009 06:48:39 -0700, demin <qdmiris@GMAIL.COM> wrote:
>On Oct 1, 8:03 pm, "Lou" <lpog...@hotmail.com> wrote:
>> ""Terjeson, Mark"" <Mterje...@RUSSELL.COM> wrote in message
>> > Hi Demin,
>> > You are very close.
>> > the PUT function converts numeric to character
>> > the INPUT function converts character to numeric
>> You're also very close. The PUT function **always** returns a character
>> value (it can convert one character value to another character value as
>> as convert a numeric value to a character value). The INPUT function
>> returns either a character or numeric value, depending on the informat
>> nothing new below, included for reference only
>> > input(oldvalue,$8.) as newvalue
>> > is correct if you are converting numeric to character.
>> > use
>> > put(oldvalue,8.) as newvalue
>> > to convert numeric to character.
>> > Now for a gotcha: if you use
>> > put(value,$8.) as value
>> > you will still end up with a numeric variable
>> > even if the PUT converts it to character. The
>> > problem of using the SAME variable name is that
>> > once the variable type has been established by
>> > the compiler looking through all of the code
>> > prior to execution, what will happen is that
>> > the PUT() function will indeed convert to string
>> > but then the assignment(=) task is next and it
>> > will see that the new temporary intermediate
>> > string value will get converted (again) to the
>> > preexisting destination variable type. And in
>> > your case it ends up as numeric all over again.
>> > So check and use/re-use variable names accordingly.
>> > Hope this is helpful.
>> > Mark Terjeson
>> > Investment Business Intelligence
>> > Investment Management & Research
>> > Russell Investments
>> > 253-439-2367
>> > Russell
>> > Global Leaders in Multi-Manager Investing
>> > -----Original Message-----
>> > From: SAS(r) Discussion [mailto:SA...@LISTSERV.UGA.EDU] On Behalf Of
>> > demin
>> > Sent: Thursday, October 01, 2009 11:38 AM
>> > To: SA...@LISTSERV.UGA.EDU
>> > Subject: how to convert a num. item to char in proc sql?
>> > how to convert a num. item to char in proc sql?
>> > I tried put, input, but doesn't work:
>> > proc sql;
>> > create view myVW as select item,input(value,$8.) as value from
>> > mytable
>> > where statistic='aaa';
>> > quit;
>> > thanks.- Hide quoted text -
>> - Show quoted text -
>Sorry, guys, my data wont work by using put:
>ODS HTML FILE='...\a.xls';
> select item, round(a,.001) format = 5.3 from exact
> order by substr(item,5,1),input(substr(item,7,2),BEST12.);
>oDS HTML CLOSE;
>Because when export to excel, the data like 0.550, 0.5 will miss the 0
>and become 0.55, 0.5, so I tried to convert to char and then export.
>but when I tried to use 'put', the result will change to 1 digit(0 or
>1), but this is not correct. I don't know if there is till has
>solution, otherwise, I only can do some change after export to excel.
> input oldvalue;
> select left(put(oldvalue,8.)) as newvalue
> from have_num;