BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
amanshrestha
Fluorite | Level 6

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?

1 ACCEPTED SOLUTION

Accepted Solutions
Sajid01
Meteorite | Level 14

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:

Sajid01_0-1697466447715.png 

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)

 

 

View solution in original post

5 REPLIES 5
maguiremq
SAS Super FREQ

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.

amanshrestha
Fluorite | Level 6

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?

Tom
Super User Tom
Super User

@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

 

andreas_lds
Jade | Level 19

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";
Sajid01
Meteorite | Level 14

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:

Sajid01_0-1697466447715.png 

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)

 

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 627 views
  • 0 likes
  • 5 in conversation