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;
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.
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;
Hey thanks for your help 🙂
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 🙂
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.
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.
thank you 🙂
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?
thanks:)
@marysmith wrote:
thank you 🙂
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?
thanks:)
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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.