Here's the scenario:
data sample;
input x;
datalines;
1
2
.
4
run;
proc sql;
select count(*) from sample; /*returns 4*/
select count(x) from sample; /*returns 3*/
quit;Is there a way to count that missing value for x?
Is there a built in variable in proc sql that represents the total number of observations?
Either just use subtraction:
proc sql;
select count(*) as N
, count(x) as NX
, count(*)-count(x) as MISSX
from sample
;
quit;
or SUM() a boolean expression. SAS evaluates boolean expressions to 1 or 0.
proc sql;
select count(*) as N
, count(x) as NX
, sum(missing(x)) as MISSX
from sample
;
quit;
Use the NMISS function
proc sql; select nmiss(x) from sample; /*returns 1*/ quit;
Very elegant answer.
So, it appears and confirmed after testing, that count(var) does not count missing values of var.
Either just use subtraction:
proc sql;
select count(*) as N
, count(x) as NX
, count(*)-count(x) as MISSX
from sample
;
quit;
or SUM() a boolean expression. SAS evaluates boolean expressions to 1 or 0.
proc sql;
select count(*) as N
, count(x) as NX
, sum(missing(x)) as MISSX
from sample
;
quit;
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 save with the early bird rate—just $795!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.