Print

Print


Thanks to all who replied.

Here is a summary of the responses.

Philippe
-----------------------------------------------------------------------

Philippe,

In reponse to your question on Allstat. You can convert character variables
to numeric by using the 'input' function within a data step, as follows:

       num = input(char,7.);

Where 7. is the format that you require for the numeric variable.
Similarly, you can convert numeric to character using the 'put' function,
and giving a character format as the second parameter.

I hope this helps you.

All the best,
Kerensa Thorne

The easiest way to do this that I know is to use the put statement in a
data step, see below:

data testdat;
format var_n 8.3 ;
set test;
var_n=put(var_c, 8.3);
run;

In this example the character variable (var_c) is converted into the
numeric variable (var_n) with a format of 8.3.
If you need to have the same name for both variables you will need to
delete var_c and then rename var_n as var_c.

I hope that this helps,
Sharon

Probably more elegant way, but see

data;
  input x$;
  y = x*1;
  cards;
10
21
32
proc means;
  var y;

As far as I know you cannot change the status of a variable, but you can
easily convert values of a character variable into numeric in a second
variable in a data step. Provided you really have only numbers into A, this
will transfer your data from character to numeric: a note about this will
appear in your log. You can rename variables in order to finally have the
same variable name as numeric instead of character.

For example :

data _dataset;
        set _dataset (rename=(A=B));
        A=B*1;
        drop B;
        run;

will result in having the same dataset structure with A changed from
character to numeric.

Hope it helps.

Kind regards
Roberto
___________

Dear Philippe,

You can use a function called "putn" into a Data Step procedure to converte
numerical values to character.  See the example.

data sample;
set sashelp.air;
air_character = left(trim(putn(AIR,"BEST3.")));
run;quit;

You can't change it directly you have to make a new variable that is
numeric using the input statement and then you can rename that variable to
your original after you've dropped your original.
e.g. if old is your character variable then the following would leave you
with a numeric variable called old:
data temp2(drop = old rename=(new=old)) ;
set temp ;
new = input(old,best.) ;
run ;

Hi Philippe

Char to numeric

data myData (drop=temp) ;
   set myData(rename=(myVar=Temp));
   myVar=input(temp,numeric_format);
run;

Numeric to Char

data myData (drop=temp) ;
   set myData(rename=(myVar=Temp));
   myVar=put(temp,Char_format);
run;

where numeric_format and Char_format are sas formats.

Dave.

P.S. Code not tested;

Dear Philippe

Your enquiry has been forwarded to me for answering.

Data manipulations of this sort are usually accomplished within the SAS
data step. Depending on the exact transformation that you are after it
could entail anything from the simplest statement to something quite
complex. The SAS Programming course covers these transformations in some
detail.
http://www.sas.com/offices/europe/uk/education/courses/prog2uk.html

Course dates are listed here (please note that ONS qualifies for a 10%
discount on SAS training):
http://www.sas.com/apps/wtraining2/coursedetails.jsp?course_code=PROG2UK&ctry=GB

Alternatively, SAS Online Documentation should be helpful.

Hope this helps.

Regards,

Geoffrey
Hi Philippe,

You can't. It's impossible. You can only make a new variable of the
opposite type by using the PUT or INPUT functions in an expression. You
could even better ask this Q on the list SAS-L. The archives of SAS-L
(http://listserv.uga.edu/archives/sas-l.html) contain many discussions and
solutions on this subject.

Regards - Jim.




For the latest data on the economy and society
consult National Statistics at http://www.statistics.gov.uk

**********************************************************************
Please Note:  Incoming and outgoing email messages
are routinely monitored for compliance with our policy
on the use of electronic communications
**********************************************************************
Legal Disclaimer  :  Any views expressed by
the sender of this message are not necessarily
those of the Office for National Statistics
**********************************************************************

______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email
______________________________________________________________________