BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
marysmith
Calcite | Level 5

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;

 

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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

6 REPLIES 6
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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;
marysmith
Calcite | Level 5

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 🙂

 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

Kurt_Bremser
Super User

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.

marysmith
Calcite | Level 5

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:)

Kurt_Bremser
Super User

@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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 6 replies
  • 3528 views
  • 0 likes
  • 3 in conversation