SAS Data Integration Studio, DataFlux Data Management Studio, SAS/ACCESS, SAS Data Loader for Hadoop and others

Character to numeric

Posts: 72

Character to numeric

[ Edited ]

i have variable family it contains values 0 and 1 in the sas file. but sas shows it a character variable. 

how can i convert character variable to numerical. 

Super User
Posts: 9,869

Re: Character to numeric

Posted in reply to Jahanzaib

It is usually a good idea to store boolean values in a $1. column, as numeric SAS variables use at least 3 bytes for the same Information.

To convert, use the input function.

If you positively want to change your datasets(s), consider this macro:

%macro change_to_num(ds,var);
data &ds;
set &ds(rename=(&var=_old&var));
&var = input(_old&var,best.);
drop _old&var;
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Ask a Question
Discussion stats
  • 1 reply
  • 1 like
  • 2 in conversation