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

Character to numeric

Reply
Contributor
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: 6,932

Re: Character to numeric

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;
run;
%mend;
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Ask a Question
Discussion stats
  • 1 reply
  • 193 views
  • 1 like
  • 2 in conversation