Hi all,
I have a numeric variable that contains no-numeric and missing values in some cases. I am trying to identify and remove those cases.
data have;
input return;
cards;
-0.031250
0.000000
C
.
0.186340
run;
want:
return
-0.031250
0.000000
0.186340
I know that when the variable is set to character there are different ways to do that, however when i try to convert the variable to character using the put function, the new variable will contain only zero.
Thanks
@AmirSari wrote:
Hi all,
I have a numeric variable that contains no-numeric and missing values in some cases.
This is plain impossible, so you are under some kind of misunderstanding of the numeric data type in SAS.
A numeric variable in SAS can only contain numbers or missing values, period. You can define special missing values (apart from .), but they're still missing values.
Non-numeric data can only be stored in character variables.
So go back and review your post
Plz take a look at notdigit function
if notdigit(variable)=0;
You question shows a bit of confusion.
A numeric variable cannot contain letters.
To read dirty data, you need to read as a character, then test that it's a valid number then save as a numeric.
Something like:
data HAVE;
input RETURNC $;
RETURN=input(RETURNC,?? dollar32.);
if RETURN ne .;
cards;
-0.031250
0.000000
C
.
0.186340
run;
RETURN |
---|
-0.03125 |
0.00000 |
0.18634 |
@AmirSari wrote:
Hi all,
I have a numeric variable that contains no-numeric and missing values in some cases.
This is plain impossible, so you are under some kind of misunderstanding of the numeric data type in SAS.
A numeric variable in SAS can only contain numbers or missing values, period. You can define special missing values (apart from .), but they're still missing values.
Non-numeric data can only be stored in character variables.
So go back and review your post
When reading from an external file, @ChrisNZ has provided the cleanest solution. It reads data as you want it, and the code has no ERRORs or WARNINGs of any kind.
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.