DATA Step, Macro, Functions and more

Help: Character values have been converted to numeric values at the places given by:

Accepted Solution Solved
Reply
Contributor
Posts: 63
Accepted Solution

Help: Character values have been converted to numeric values at the places given by:

Hi,

 

I am getting this note and I dont know what to do. This is my code. Does anybody know?

Thanks in advance!

 

data drug_groups;
set datensatz_drugs;
if NIS_Nummer="6513" then allergy=1;
if NIS_Nummer="6699" then allergy=1; /*N=2*/

if NIS_Nummer="2047" then antibiotics=1;
if NIS_Nummer="6613" then antibiotics=1;
if NIS_Nummer="6623" then antibiotics=1;
if NIS_Nummer="6725" then antibiotics=1;
if NIS_Nummer="7030" then antibiotics=1; /*N=5*/

if NIS_Nummer="6622" then antidiabetic=1;
if NIS_Nummer="6629" then antidiabetic=1;
if NIS_Nummer="6649" then antidiabetic=1;
if NIS_Nummer="6818" then antidiabetic=1;
if NIS_Nummer="6819" then antidiabetic=1;  /*N=5*/

run;

 


Accepted Solutions
Solution
‎05-16-2018 09:29 AM
Super User
Super User
Posts: 9,855

Re: Help: Character values have been converted to numeric values at the places given by:

Posted in reply to marysmith

Right, there is your answer, nis_nummer is a numeric, and you are treating it as a character, hence why you get the warnings.

Why do you want to convert it to character?  If you do, where did the data come from?  I would change the import process, I assume you read in an Excel (bad data format) file using proc import (guessing procedure), and have now ended up with something you didnt want, surprisingly!  As for making the other ones character, again why?  Are they defined before in the dataset, or are they new to this datastep, if new then simply declare them and use them as character.  Again, we are only seeing a tiny fragment of the whole, so can't really say, post test data in the form of a datastep, then show what you want out at the end, otherwise we are just guessing.

View solution in original post


All Replies
Super User
Super User
Posts: 9,855

Re: Help: Character values have been converted to numeric values at the places given by:

Posted in reply to marysmith

In future, please show some test data in the form of a datastep, otherwise we are just guessing.

Is NIS_Number a number or character?  Has Alergy, antibiotics, or antidiabetic been defined as character or numeric?

Also, you can shrink your code drastically by:

data drug_groups;
  set datensatz_drugs;
  if nis_nummer in ("6513","6699") then allergy=1;
  if nis_nummer in ("2047"...) then antibiotics=1;
...
run;

Or even:
...
  select(nis_nummer);
    when("6513","6699") allergy=1;
    when("2047"...) antibiotics=1;
...
  end;
Contributor
Posts: 63

Re: Help: Character values have been converted to numeric values at the places given by:

Hey thanks for your help Smiley Happy

I did a proc content datastep and NIS_nummer is a numeric variable. How to transform it into a character variable?

 

And the variables I created allergy, antibiotics, antidiabetics ... should be character variable but are also defined as numeric variables. How can I change that?

 

Cheers Smiley Happy

 

Solution
‎05-16-2018 09:29 AM
Super User
Super User
Posts: 9,855

Re: Help: Character values have been converted to numeric values at the places given by:

Posted in reply to marysmith

Right, there is your answer, nis_nummer is a numeric, and you are treating it as a character, hence why you get the warnings.

Why do you want to convert it to character?  If you do, where did the data come from?  I would change the import process, I assume you read in an Excel (bad data format) file using proc import (guessing procedure), and have now ended up with something you didnt want, surprisingly!  As for making the other ones character, again why?  Are they defined before in the dataset, or are they new to this datastep, if new then simply declare them and use them as character.  Again, we are only seeing a tiny fragment of the whole, so can't really say, post test data in the form of a datastep, then show what you want out at the end, otherwise we are just guessing.

Super User
Posts: 10,592

Re: Help: Character values have been converted to numeric values at the places given by:

Posted in reply to marysmith

If NIS_Nummer is numeric, omit the quotes:

if NIS_Nummer = 6513 then allergy = 1;

Otherwise, if the variables used in the "then" branch exist already and are of type character, use quotes there.

 

Strong hint: always post the log! It contains valuable information exactly where the problem lies.

Use the {i} button and see my footnotes for hints on posting code, logs and other text that must not be changed by the forum webapp.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Contributor
Posts: 63

Re: Help: Character values have been converted to numeric values at the places given by:

Posted in reply to KurtBremser

thank you Smiley Happy

you are right NIS_Nummer is a numeric variable, but I thought it is a character variable. How do i convert it into a character variable?

thanksSmiley Happy

Super User
Posts: 10,592

Re: Help: Character values have been converted to numeric values at the places given by:

Posted in reply to marysmith

@marysmith wrote:

thank you Smiley Happy

you are right NIS_Nummer is a numeric variable, but I thought it is a character variable. How do i convert it into a character variable?

thanksSmiley Happy


Why would you want to? If it only contains 4-digit numbers below 8192, define it (at creation/import time) as numeric with length 3 (saving space), and you do not have to write all the quotes. If you have numbers up to 9999, you can still use length=4 and spare the quotes.

If you really want to have it as character, define it so when data is read into SAS.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 112 views
  • 0 likes
  • 3 in conversation