Contributor
Posts: 20

# COUNT MISSING AND NON MISSING ACROSS COLUMNS

Hello,

I wan to write a program to count missing and non missing values across the columns. I got a program from someone like this-

data temp;
input x y z a b\$;
cards;
1 23 24 50 AA
1 . 24 50 AC
1 13 . 50 AB
1 23 . 50 .
;
run;

proc contents data=temp out=cols noprint;
run;

data _null_;
set cols nobs=total;
call symputx('totvar', total);
run;

data outdata;
set temp;
totalvar=&totvar;
totmiss=cmiss(of x--b);
totnonmiss=totalvar- cmiss(of x--b);
proc print ;
run;

and I got the correct result.

 x y z a b totalvar totmiss totnmiss 1 23 24 50 AB 5 1 4 1 . 24 50 AC 5 0 5 1 13 . 50 AB 5 1 4 1 23 . 50 5 2 3

But in the above program, there are 4 observations, and NOBS is used to calculate the number of observations, so how can we calculate number of variables. I mean when we use "set cols nobs=total;" the value of total should be 4 and the value of &totvar should also be 4, but in output it is showing 5. How? I am confused. I am not able to understand this. Please help me.

Super User
Posts: 10,258

## Re: COUNT MISSING AND NON MISSING ACROSS COLUMNS

``````proc contents data=temp out=cols noprint;
run;

data _null_;
set cols nobs=total;
call symputx('totvar', total);
run;``````

The output dataset of proc contents (cols) contains one observation for each variable in the input dataset (temp).

So when that is read in the next data step, the nobs comes from cols (not from temp!) and therefore is equivalent to the count of variables in temp.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Contributor
Posts: 20

## Re: COUNT MISSING AND NON MISSING ACROSS COLUMNS

Thank you so much..!!

Super User
Posts: 10,784

## Re: COUNT MISSING AND NON MISSING ACROSS COLUMNS

``````data temp;
input x y z a b\$;
cards;
1 23 24 50 AA
1 . 24 50 AC
1 13 . 50 AB
1 23 . 50 .
;
run;

%let dsid=%sysfunc(open(temp));
%let totvar=%sysfunc(attrn(&dsid,nvar));
%let dsid=%sysfunc(close(&dsid));

%put &totvar;``````
Discussion stats
• 3 replies
• 1841 views
• 0 likes
• 3 in conversation