BookmarkSubscribeRSS Feed
HeatherNewton
Quartz | Level 8

 do you know if sas automatically turn null into 0 in any case?

 

in what I see, when sas read in from files other than sas dataset

it turn null into zero

why is this??

our files are iff, lets say it is some text file

7 REPLIES 7
mkeintz
PROC Star

Assuming by "null", you mean a blank character, and assuming you are reading values via the INPUT statement, then SAS does NOT by default convert a null into a zero (we are discussing numeric variables here).  Instead, the numeric variable is assigned a special missing value (typically printed out as a naked period), when read from a "null".

 

I.e. this program:

data t;
  input @1 x 1.  @3 y 1. ;
  put (_all_) (=);
datalines;
1 1
2  
  3
run;

produces this on the sas log (note the dots).

x=1 y=1
x=2 y=.
x=. y=3
NOTE: The data set WORK.T has 3 observations and 2 variables.

A missing value, by default, is not treated as a zero, although there are some SAS functions and statements that can treat missing values as zeroes.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
andreas_lds
Jade | Level 19

If a data step is used to read the files, a custom informat could change missing (aka null) to 0 automatically.

Amir
PROC Star

Hi,

 

Please share an example data step with instream data (e.g., datalines), so that we can replicate the issue to assist with a solution.

 

Depending upon how you are reading in the data and viewing it, the missing= option might be worth checking, as the page says "Specifies the character to print for missing numeric values."

 

 

Thanks & kind regards,

Amir.

ballardw
Super User

@HeatherNewton wrote:

 do you know if sas automatically turn null into 0 in any case?

 

in what I see, when sas read in from files other than sas dataset

it turn null into zero

why is this??

our files are iff, lets say it is some text file


What is your current setting for the MISSING option? You can check by running this code:

Proc options option=missing;
run;

The output in the log will look something like:

49   Proc options option=missing;
50   run;

    SAS (r) Proprietary Software Release 9.4 

 MISSING=.         Specifies the character to print for missing numeric
                   values.

If your result shows Missing=0 then your setting is displaying zero when the value is missing.

Otherwise show the code you are using to read one of these files and a few lines of the text file data that exhibit this behavior.

 

 

PaigeMiller
Diamond | Level 26

@HeatherNewton 

Unless you have subject matter knowledge that allows you to know that null should be treated as zeros, do NOT do this. Nulls should be treated as missing without such subject matter knowledge.

--
Paige Miller
MelissaM
Obsidian | Level 7
I was so hoping someone would mention that 'missing information' is rarely equal to a numeric 'zero'. Thank you, Paige, for calling this out! 🙂
PaigeMiller
Diamond | Level 26

@HeatherNewton please mark one of the above replies as correct, whichever one you think is correct.

--
Paige Miller

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 7 replies
  • 493 views
  • 3 likes
  • 7 in conversation