Dear Community ,
I'm working on the data to report the category of numeric variable( Weight ).
my dataset looks like below:
ID Weight Wtcat
1 50
2 60
3 80
4 60,75
5 75
6 D
Wtcat is the new column to report the categories of weight e.g <50= cat1 , 50-60= cat2 etc.....)
Here is my pgm:
DATA new;
SET old;
LENGTH Wtcat $20;
IF WEIGHT <50.0 THEN Wtcat ='<50 Kg';
IF WEIGHT=>50.0 and Wtcat <60.0 THEN Wtcat ='50-60 Kg';
IF WEIGHT=>60.0 and Wtcat <70.0 THEN Wtcat ='60-70 Kg';
.......................................................
RUN;
I got the note below in my log:
ID=4 Wtcat=<50 Kg _ERROR_=1
_N_=109
NOTE: Invalid numeric data, WEIGHT='57,7' , at line 290 column 3.
The same issue for ID=6
NOTE: Invalid numeric data, WEIGHT='D' , at line 286 column 4
And ID=4 was reported as <50 rather than >=50 because of the comma in weight value.
So I would like to fix this.
Thank you
I got the note below in my log:
ID=4 Wtcat=<50 Kg _ERROR_=1
_N_=109
NOTE: Invalid numeric data, WEIGHT='57,7' , at line 290 column 3.
This can't possibly come from the data you are showing. Please show us the actual data you are using in data set OLD, by creating working SAS data step code typing it in yourself (and testing it to make sure it works) or via these instructions.
NOTE: Invalid numeric data, WEIGHT='D' , at line 286 column 4
SAS can't read the letter D in as a numeric. So WEIGHT will be set to missing on this row.
And ID=4 was reported as <50 rather than >=50 because of the comma in weight value.
Change the comma to a decimal point (a dot) and it will work. Or, use the COMMAX. informat used to read in the data to use commas to separate the integer from the decimal.
your code does not look correct. also you should wrap it in if ^missing(weight) then do. How do you want to classify wtcat if weight is missing? you realize that missing weight is also <50 and would be classified as wtcat='<50 kg'. I don't think that's what you intended. also you need to use weight in your 2nd and 3rd if statement.
you're getting that error because weight is evidently not numeric, but rather character, and you are trying to compare a character to a number. you need to convert your character weight variable to numeric to do a NUMERIC comparison. also, what does weight D mean?
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.