Avoid Surprises in Data Analysis Across Platforms
The Challenge
A single NULL can change everything. In hybrid workflows, SAS and databases like Snowflake don’t always treat missing values the same way. If you don’t understand where your NULL value is being processed, you risk reports that look correct but aren’t. This blog explores how those differences arise and how to guard against them.
_______________________________________________________________________________________________________________________
What You Need to Know
NULL represents an absence of data. NULL values are excluded from analytics by default. They cannot be sorted or evaluated with standard comparison operators or functions.NULL values into missing values. SAS supports 28 types of missing values, which means missing values are included in analytics. They can be sorted and evaluated._______________________________________________________________________________________________________________________
An Example
The sashelp.heart dataset is derived from the Framingham Heart Study, a long-term cardiovascular study. It contains 5,209 observations (one per patient) and 17 columns, including alive/dead status, age, sex, and clinical indicators such as cholesterol status.
The Chol_Status field contains values: High, Borderline, Desirable, and missing.
Goal
Find the proportion of alive and dead patients where cholesterol status is not High.
SAS CODE
proc freq data=sashelp.heart;
tables Status*Chol_Status;
where Chol_Status NE 'High';
run;
SAS Output
Snowflake Comparison
When sashelp.heart is copied to Snowflake via implicit passthrough, SAS missing values are translated to NULL . Running the same query in Snowflake produces different results:
| PROC FREQ Output | SAS | Snowflake | Difference |
| Status-Alive | 2,267 | 2,184 | 83 |
| Status-Dead | 1,151 | 1,082 | 69 |
| Chol_Status-Missing | 152 | 0 | 152 |
_______________________________________________________________________________________________________________________
Options for Handling Database NULL Values
1. Modify the WHERE Clause
Explicitly include NULL values to align Snowflake results with SAS:
proc freq data=snowlib.heart;
tables Status*Chol_Status;
where Chol_Status in ('Borderline','Desirable') or Chol_Status is NULL;
run;
2. Force SAS Processing
Use the LIBNAME option DIRECT_SQL=NOWHEREto prevent WHERE clauses from being passed to the database. This forces SAS to process the data locally:
libname snowlib snow user=... password=... direct_sql=nowhere;
_______________________________________________________________________________________________________________________
How to Validate Where Processing Occurs
PROC FREQ is one of the SAS procedures that SAS/ACCESS can push down to the database. To confirm enable tracing options:
options sastrace=',,,ds' sastraceloc=saslog nostsuffix sql_ip_trace=(note,source);
The log will show the SQL passed to Snowflake. You can also confirm query execution within Snowflake Monitoring - Query Details.
_______________________________________________________________________________________________________________________
Summary
Differences in NULL handling between SAS and DBMS platforms like Snowflake can lead to subtle but significant discrepancies in results. What looks like a small detail — whether missing values are included or excluded — can ripple into compliance reports, clinical trial outcomes, or financial dashboards.
To avoid surprises:
NULL values in your WHERE clauses.By understanding these differences and planning accordingly, you can ensure your hybrid workflows remain accurate, reproducible, and trustworthy.
_______________________________________________________________________________________________________________________
Resources
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!
The rapid growth of AI technologies is driving an AI skills gap and demand for AI talent. Ready to grow your AI literacy? SAS offers free ways to get started for beginners, business leaders, and analytics professionals of all skill levels. Your future self will thank you.