BookmarkSubscribeRSS Feed
Jahanzaib
Quartz | Level 8

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. 

1 REPLY 1
Kurt_Bremser
Super User

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;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 680 views
  • 1 like
  • 2 in conversation