When I use two numeric variables to create a third variable, I get a warning in the log saying that "Numeric values have been converted to character values at the places given by: (Line):(Column). 4106:28 4107:10"
I have used the code below:
if travel_time<=30 then acs=1; /*accessible*/
else acs=0; /*not accessible*/;
When I check my proc contents for "acs" variable created above, it shows that the type is Char (len=29), while travel_time is of numeric type (len=8). Can you guy suggest any solution to this? Why am I having this error? Shouldn't I have numeric value for acs when travel_time is all numeric?
Hello @amanshrestha
Your question is "Shouldn't I have numeric value for acs when travel_time is all numeric?"
I should be numeric as I see it. My code is given below.
data want;
travel_time = 29;
if travel_time<=30 then acs=1;
else acs=0;
run;
proc contents data=want;
run;
I see this from proc contents:
It is possible that you might have defined acs as character variable. In that event you will be receiving the Note you are seeing.
In that event, avoid the Note, use acs="1" and acs ="0" i.e. enclose values in quotes (double or single)
Are you able to show your actual code?
You say you use two numeric variables to create the third, but you're only showing one? I'm just a little confused. Maybe I'm missing something.
My bad, it was just one variable travel_time
if travel_time<=30 then acs=1; /*accessible*/
else acs=0; /*not accessible*/
travel_time is a numeric variable with values ranging from 9 to 104. But, when I dichotomize it into an acs variable, the acs variable becomes the character. Should not acs be numeric?
@amanshrestha wrote:
My bad, it was just one variable travel_time
if travel_time<=30 then acs=1; /*accessible*/
else acs=0; /*not accessible*/
travel_time is a numeric variable with values ranging from 9 to 104. But, when I dichotomize it into an acs variable, the acs variable becomes the character. Should not acs be numeric?
You have to show the whole code.
For example I assume those two statements are part of some data step like this:
data want;
set have;
if travel_time<=30 then acs=1;
else acs=0;
run;
If there is already a variable named ACS in the source dataset then ACS will defined by the SET statement. So when you try to assign a numeric values like 0 or 1 to it then SAS will convert the number to a character string.
For a demonstration run this code:
data have;
do travel_time=10,30,50 ;
output;
end;
length acs $29;
run;
data want;
set have;
if travel_time<=30 then acs=1;
else acs=0;
put travel_time= acs=:$quote.;
run;
You will see this in the LOG
479 data want; 480 set have; 481 if travel_time<=30 then acs=1; 482 else acs=0; 483 put travel_time= acs=:$quote.; 484 run; NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column). 481:31 482:12 travel_time=10 acs=" 1" travel_time=30 acs=" 1" travel_time=50 acs=" 0" NOTE: There were 3 observations read from the data set WORK.HAVE. NOTE: The data set WORK.WANT has 3 observations and 2 variables. NOTE: DATA statement used (Total process time): real time 0.01 seconds cpu time 0.03 seconds
If acs is a char variable, why don't you assign quoted values to it?
if travel_time <= 30 then acs = "1"; /*accessible*/
else acs = "0";
Hello @amanshrestha
Your question is "Shouldn't I have numeric value for acs when travel_time is all numeric?"
I should be numeric as I see it. My code is given below.
data want;
travel_time = 29;
if travel_time<=30 then acs=1;
else acs=0;
run;
proc contents data=want;
run;
I see this from proc contents:
It is possible that you might have defined acs as character variable. In that event you will be receiving the Note you are seeing.
In that event, avoid the Note, use acs="1" and acs ="0" i.e. enclose values in quotes (double or single)
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.