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

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

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

@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

  • is it about a SAS dataset or an external file that you want to import into SAS
  • if a SAS dataset, run a proc contents and show the type of the variable in question. Also run a proc print of that variable and show values that are puzzling you
  • if an external file, post some example lines, and what you want have in the resulting SAS dataset

View solution in original post

5 REPLIES 5
novinosrin
Tourmaline | Level 20

Plz take a look at notdigit function

 

if notdigit(variable)=0;

ChrisNZ
Tourmaline | Level 20

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

 

 

Kurt_Bremser
Super User

@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

  • is it about a SAS dataset or an external file that you want to import into SAS
  • if a SAS dataset, run a proc contents and show the type of the variable in question. Also run a proc print of that variable and show values that are puzzling you
  • if an external file, post some example lines, and what you want have in the resulting SAS dataset
AmirSari
Quartz | Level 8
Thanks for your reply. I think I understand the numeric data type in SAS. I am working with an external dataset in which the missing values are displayed both as "." and "C" and that's why I got confused. Thanks for clarification, though.

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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
  • 5 replies
  • 7456 views
  • 8 likes
  • 4 in conversation