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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.