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

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

 

1 ACCEPTED SOLUTION

Accepted Solutions
WarrenKuhfeld
Rhodochrosite | Level 12

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

14 REPLIES 14
WarrenKuhfeld
Rhodochrosite | Level 12

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
Astounding
PROC Star

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

yangx
Obsidian | Level 7

Hello,

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

 

Xiumei

Astounding
PROC Star

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.

PGStats
Opal | Level 21

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
yangx
Obsidian | Level 7

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

 

Reeza
Super User

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. 

ballardw
Super User

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.

 

Astounding
PROC Star

Now it becomes clear.

 

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

yangx
Obsidian | Level 7

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

 

Xiumei

 

WarrenKuhfeld
Rhodochrosite | Level 12

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
WarrenKuhfeld
Rhodochrosite | Level 12

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. 

yangx
Obsidian | Level 7

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

 

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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
  • 14 replies
  • 1784 views
  • 1 like
  • 6 in conversation