BookmarkSubscribeRSS Feed
pransh
Calcite | Level 5

i have been working on a project where I need to merge data

so in one dataset longitude is in character format and in other its in numeric format.

When i try to convert the one in character to numeric the log says "  numeric values have been converted to character" 

 

Also i double checked , I m using the correct syntax for the conversion

new_variable = input(original_variableinformat.);

 

I dont know why then also it says numeric values have been converted to character

 

I am assuming there might be some observations in the variable which is character and rest are numeric?( although running proc contents show that the format for that particular variable is character)

 

SO how to look for those observations

6 REPLIES 6
awesome_opossum
Obsidian | Level 7

There might be an easier way, but often in this situation I actually create a numeric var like so. I realize most people don't do this.

 

data want; set have; 
numvar = .;  /* create "empty" numvar */ 
numvar = charvar; 
run; 

If you do this, the numvar will return blanks "." for any charvar entries that aren't actually a number.  So you can just pull up a list of the blanks, and review what they were in the corresponding charvar:

 

proc sql; create table numvar_blanks
as select
numvar, 
charvar
from want
where numvar = .
    /* optional */ and charvar ^= ''; 
quit; 

Once you've sorted out what to do with any wonky cases, you can just drop the charvar and rename the numvar as desired, perhaps in the first datastep. 

 

pransh
Calcite | Level 5

hi ,

it just creates two  new variable numvar and charvar with all the observations as   ' .  '

awesome_opossum
Obsidian | Level 7
In my code, charvar is your original_variable, numvar is your new_variable.
pransh
Calcite | Level 5
hi
it did convert but there were no . in the new variable
and the log now read character variables have been converted to numeric

can it be a case where some of the zeros were written as o and decimal places as commas?
ballardw
Super User

" When i try to convert the one in character to numeric the log says " numeric values have been converted to character" "

 

Input function requires character values as the first parameter. If you see that message then the value/variable you provided is already numeric. So SAS has to convert it to character for the Input to work. So perhaps you are attempting to change the wrong variable?

Show us the results of running Proc Contents on BOTH data sets and tell us which ones are the ones you need to be the same.

 

NO variable in SAS will be both numeric and character. A value may be character and only hold digits but it is still character.

You also need to consider any FORMAT assigned to a variable. The value may look "character" if the format assigns text to numeric values. One not uncommon is to have a Sex or Gender variable with numeric values like 1 and 2 but a format that assigns more usable to humans of "Male" and "Female". Proc Contents will show the assigned format and if we see something with a non-SAS supplied name that could be the case with your data.

PaigeMiller
Diamond | Level 26

@pransh wrote:

 

I am assuming there might be some observations in the variable which is character and rest are numeric?( although running proc contents show that the format for that particular variable is character)

 

SO how to look for those observations


This has nothing to do with observations. In a SAS data set, a variable is either character for all observations, or numeric for all observations. As far as the rest of your questions, when there's something in the log that you don't understand, show us the ENTIRE log for this PROC or DATA step. Not small parts of the log, not the parts of the log that you think we need, show us the ENTIRE log for this PROC or DATA step.

 

Please copy the log as text and paste it into the window that appears when you click on the </> icon. DO NOT SKIP THIS STEP.

PaigeMiller_0-1663012019648.png

--
Paige Miller

sas-innovate-white.png

Missed SAS Innovate in Orlando?

Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.

 

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 1045 views
  • 0 likes
  • 4 in conversation