sas >> converting numeric values to character

by quecher » Thu, 14 Dec 2006 08:23:50 GMT

I'm having problems converting my variable 'laystage', which is numeric
(BEST12.), into a character variable. I created a new variable 'wave'
for this, using "wave = laystage". However, the results are very
confusing. Wave is still a numeric variable. The PUT statement seems to
be doing the exact opposite - converting character values to numeric.
Can anyone tell me what is going wrong? FYI, the values of laystage
range from -7 to 7, in integers or numbers ending in .5.

Here are the results from my Log window:

109 data mylib.loggers030405append4finalwoATFL;
110 set mylib.loggers030405append4finalwoATFL;
111 wave = PUT (laystage, BEST12.);

NOTE: Character values have been converted to numeric values at the
places given by:
(Line):(Column).
111:8
NOTE: There were 1427 observations read from the data set
MYLIB.LOGGERS030405APPEND4FINALWOATFL.
NOTE: The data set MYLIB.LOGGERS030405APPEND4FINALWOATFL has 1427
observations and 74
variables.
NOTE: DATA statement used (Total process time):
real time 0.13 seconds
cpu time 0.04 seconds

And here's what PROC CONTENTS displays after the conversion:
# Variable Type Len Format Informat Label
31 laystage Num 8
laystage
74 wave Num 8
laystage in text format


sas >> converting numeric values to character

by NordlDJ » Thu, 14 Dec 2006 09:23:03 GMT


> -----Original Message-----

The note about character conversion that you see suggests to me that the variable, WAVE, already exists as a numeric variable in the file mylib.loggers030405append4finalwoATFL . In order to do the conversion, WAVE must either not exist previous to the assignment statement, or it must be defined as a character variable.

Hope this is helpful,

Dan

Daniel J. Nordlund
Research and Data Analysis
Washington State Department of Social and Health Services
Olympia, WA 98504-5204

sas >> converting numeric values to character

by tobydunn » Thu, 14 Dec 2006 10:24:18 GMT

Quecher ,

Once a variables type is set it is set, you cannot change that fact. To do
what you want and given that Wave is already defined a numeric you will
first have to rename or drop it, then recreate wave the way that you wish.
The Put function is creating a character value, it is all it can do.
However since the variable Wave is already defined as a numeric on your data
set the conversion note you see is from SAS converting the character value
from the Put function back into a numeric so it will fit inside of your
variable Wave.



Data MyLib.Loggers030405Append4FinalWOATFL ;
Set MyLib.Loggers030405Append4FinalWOATFL ( Drop = Wave ) ;

Wave = Put ( LayStage , 8.1 -L ) ;

Run ;

I also see your not much on a naming scheme that is readable much less
understandable. Were it I, I would rename your data sets and variable names
to that has more meaning while not being quite so long or cryptic.


Toby Dunn

To sensible men, every day is a day of reckoning. ~John W. Gardner

The important thing is this: To be able at any moment to sacrifice that
which we are for what we could become. ~Charles DuBois

Don't get your knickers in a knot. Nothing is solved and it just makes you
walk funny. ~Kathryn Carpenter






From: quecher < XXXX@XXXXX.COM >
Reply-To: quecher < XXXX@XXXXX.COM >
To: XXXX@XXXXX.COM
Subject: converting numeric values to character
Date: Wed, 13 Dec 2006 16:23:50 -0800

I'm having problems converting my variable 'laystage', which is numeric
(BEST12.), into a character variable. I created a new variable 'wave'
for this, using "wave = laystage". However, the results are very
confusing. Wave is still a numeric variable. The PUT statement seems to
be doing the exact opposite - converting character values to numeric.
Can anyone tell me what is going wrong? FYI, the values of laystage
range from -7 to 7, in integers or numbers ending in .5.

Here are the results from my Log window:

109 data mylib.loggers030405append4finalwoATFL;
110 set mylib.loggers030405append4finalwoATFL;
111 wave = PUT (laystage, BEST12.);

NOTE: Character values have been converted to numeric values at the
places given by:
(Line):(Column).
111:8
NOTE: There were 1427 observations read from the data set
MYLIB.LOGGERS030405APPEND4FINALWOATFL.
NOTE: The data set MYLIB.LOGGERS030405APPEND4FINALWOATFL has 1427
observations and 74
variables.
NOTE: DATA statement used (Total process time):
real time 0.13 seconds
cpu time 0.04 seconds

And here's what PROC CONTENTS displays after the conversion:
# Variable Type Len Format Informat Label
31 laystage Num 8
laystage
74 wave Num 8
laystage in text format

_________________________________________________________________
All-in-one security and maintenance for your PC. Get a free 90-day trial!
http://clk.atdmt.com/MSN/go/msnnkwlo0050000002msn/direct/01/?href=http ://clk.atdmt.com/MSN/go/msnnkwlo0050000001msn/direct/01/?href= http://www.windowsonecare.com/?sc_cid=msn_hotmail

sas >> converting numeric values to character

by quecher » Thu, 14 Dec 2006 14:30:12 GMT

hat worked liked a charm. thanks for the explanation.

-quecher

toby dunn wrote:


Similar Threads

1. Convert numeric values into characters while using PROC SQL INSERT INTO

2. Convert numeric values into characters while using PROC SQL

3. converting decimal characters to numeric values

Hello,
I have a text file with the format as (values seperated by vertical
bars | ):

line 1  |     0.42  |    1.28  |   4.62 |    2.11 |

data perc;
  infile outtxt pad lrecl=100;
  array percent[4]  percent1-percent4;
  input lines $char100.;
  do i=2 to 5;
     percent[i-1]=input(scan(lines, i, '|'), 5.2);
  end;
run;

My question is why the values for percent1-percent4 become: 0  0.01
0.04 0.02 ?
Thank you for your help!

Yvonne

4. convert characters to numeric values with input:

5. Convert to numeric where Date field Numeric and Character

I have a  date field can be numeric and populated or
character and blank (only these 2 scenarios)
if it's populated it has this format MMDDYY10.  numeric and if it's
character then it's just blank.


so what i need is for the numeric date to look like this: Numeric,
Length 8, Format 11.  and look like 20100214      and if it's
character then convert it so it looks like 20100214.

Thank you

6. coverting character values to numeric values

7. Numeric value (18 digit) to character value

8. a good practice to convert character to numeric