DATA Step, Macro, Functions and more

Without missing statement why do numeric variables accept one character value?

Accepted Solution Solved
Reply
Contributor
Posts: 23
Accepted Solution

Without missing statement why do numeric variables accept one character value?

Hello,

 

I encountered a problem that I couldn't understand. I have a sas program to read a file into sas, which contains number fields that have single character values as missing value. In my program, I didnt' specify "missing A D; " statement, but the program read the value of 'A', and 'D', and create a sas dataset with the value of 'A', 'D', there is no errro message in the log file.  I am using SAS 9.4. I am just wondering if SAS 9.4 automatically convert character value for numeric field as missing value or not. Thanks.

 

Xiumei

 


Accepted Solutions
Solution
‎09-21-2017 03:30 PM
SAS Super FREQ
Posts: 508

Re: Without missing statement why do numeric variables accept one character value?

Posted in reply to WarrenKuhfeld

There are 28 missing values: .A - .Z and . and also ._

 

.NA is not defined.  The MISSING statement is used to read A-Z and _ as numeric missing values. 

View solution in original post


All Replies
SAS Super FREQ
Posts: 508

Re: Without missing statement why do numeric variables accept one character value?

It does not work for me.



data x;
   input a d;
   cards;
1 2
A D
3 4
;   

proc print; run;

                                 Obs    a    d

                                  1     1    2
                                  2     .    .
                                  3     3    4
Super User
Posts: 6,921

Re: Without missing statement why do numeric variables accept one character value?

Almost certainly, your new variable is character not numeric.  You can run a PROC CONTENTS to find out.

Contributor
Posts: 23

Re: Without missing statement why do numeric variables accept one character value?

Posted in reply to Astounding

Hello,

Thanks for your prompt reply. But the variable is number, not character.

 

Xiumei

Super User
Posts: 6,921

Re: Without missing statement why do numeric variables accept one character value?

There are various places that the MISSING option can be specified:

 

http://support.sas.com/documentation/cdl/en/lesysoptsref/69799/HTML/default/viewer.htm#n0qamf3yfjtwz...

 

Have you checked them all?

 

It wouldn't hurt to post the log from your DATA step.

Esteemed Advisor
Posts: 5,621

Re: Without missing statement why do numeric variables accept one character value?

When reading a text file (not a dataset) SAS does not convert character data into special missing values, unless you use the missing statement. It will however convert character data into normal missing values without generating an error message if the ?? modifier is used in conjunction with the informat in the input statement. 

PG
Contributor
Posts: 23

Re: Without missing statement why do numeric variables accept one character value?

Hello,

Thanks for all the replies, but please see my program below, and data file has been attached.

filename data1 'try.txt';
data data1;
  infile data1 LRECL=4096 dlm='|' missover dsd;
  informat pcr98    $CHAR32. ;
  input ID  glucose3  tchol3  hdl3  ldl3  trig3  pcr98 $ ;
  label ID="participant id number"
        glucose3="Glucose"
        tchol3="Total cholesterol"
        hdl3="HDL"
        ldl3="LDL"
        trig3="Triglycerides"
        pcr98="completed by:";
run;
proc print data=data1;
run;
proc contents data=data1;
run;

The variables here glucode3, tchol3, hdl3, ldl3 are all number fields, but in the data file, there are values of ".D", ".U".  Without specifying "MISSING" statement, sas reads these value into the dataset. When I use proc freq, these values are considered as missing values. My qestion is why SAS didn't give any error messages in the log file. thanks.

 

xiumei

 

Super User
Posts: 23,980

Re: Without missing statement why do numeric variables accept one character value?

Because .D and .U are missing values in SAS.

 

Any .A-.Z is considered missing by default and SAS treats data that's in that format as missing. 

Super User
Posts: 13,913

Re: Without missing statement why do numeric variables accept one character value?

You should provide a sample of the data file and exactly how you read it into SAS.

Post the code and example data into a code box opened with the forum {i} menu icon.

 

If you see values of A and D then it is most likely that the variable is not actually numeric but character. The exception would be if you were reading data using a custom informat that assigns special missing values of .A .D or similar.

 

proc format library=work;
invalue someinput
1 - 10=_same_
"A" = .A
"D" = .D
;
run;

data example;
   informat x someinput.;
   input x;
datalines;
1
2
A
3
D
4
5
;
run;

If you look at the data in a SAS table viewer you will see A and D for a numeric variable

 

But:

proc freq data=example;
run;

Shows the values are missing.

 

Super User
Posts: 6,921

Re: Without missing statement why do numeric variables accept one character value?

Now it becomes clear.

 

Your data doesn't contain A and D.  It contains .A and .D instead, which SAS understands as numeric.

Contributor
Posts: 23

Re: Without missing statement why do numeric variables accept one character value?

Posted in reply to Astounding

Sorry, I don't understand, why does sas understand ".A", ".D" as numeric? then how about ".NA"? Thanks.

 

Xiumei

 

Super User
Posts: 23,980

Re: Without missing statement why do numeric variables accept one character value?

Here's the SAS documentation chapters on MISSING.

It's worth a read:

 

http://support.sas.com/documentation/cdl/en/lrcon/69852/HTML/default/viewer.htm#n1il1j711miuhrn1tp0p...

SAS Super FREQ
Posts: 508

Re: Without missing statement why do numeric variables accept one character value?

Posted in reply to Astounding

Astounding is correct.  Compare what you asked (line 2 of the data) with what you did (line 1 of the data).

 


data x;
   input a d;
   cards;
.A .D
A D
3 4
;   

proc print; run;
                                Obs    a    d

                                  1     A    D
                                  2     .    .
                                  3     3    4
Solution
‎09-21-2017 03:30 PM
SAS Super FREQ
Posts: 508

Re: Without missing statement why do numeric variables accept one character value?

Posted in reply to WarrenKuhfeld

There are 28 missing values: .A - .Z and . and also ._

 

.NA is not defined.  The MISSING statement is used to read A-Z and _ as numeric missing values. 

Contributor
Posts: 23

Re: Without missing statement why do numeric variables accept one character value?

Posted in reply to WarrenKuhfeld

Thanks for the reply. Now I understand for .A-.Z, ._, no need to specify "MISSING" statement in SAS program, sas will consider these values as missing, but for A-Z, MISSING statement need to specified delibrately in sas program, such as MISSING A D. Thanks again!

 

Xiumei

 

 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 14 replies
  • 228 views
  • 1 like
  • 6 in conversation