Reputation: 109
I'm dealing with a continuous variable and it has values like <3, NOTE and NOTE1. I want to get rid of these values and make it missing values. what will be the command line for this?
Thanks
Upvotes: 1
Views: 265
Reputation: 8513
You can use the input function to convert from character to numeric.
new_var = input(old_var, ?? best.);
By supplying the ??
option immediately before the informat, you are instructing SAS to suppress any warning messages or notes it would normally print when it encounters an issue applying the informat.
The nice thing about this approach is that it's simple, and it communicates your intent to convert the value from string to numeric while ignoring any type conversions that you encounter.
Upvotes: 0
Reputation: 1120
You can simply multiply the variable by 1; this replaces all numeric values stored as character values with their numeric counterparts and populates all character values as missing:
data temp;
input var $;
datalines;
Hello
1
<3
3
Note1
5
;
run;
data temp2;
set temp;
var2 = var * 1;
run;
Note that this may give a warning depending on how many character values are being replaced, but this warning does not cause problems with the resultant dataset.
Upvotes: -1
Reputation: 21264
If your variable has character values then it's a character value, not numeric. You'll need to fix that as well. I would suggest using the anyalpha() function to determine if you can convert it to a number.
If anyalpha(old_var)=0 then new_var = input(old_var, best12.);
Upvotes: 2