Date: Tue, 7 Dec 2004 15:15:54 -0500
Reply-To: Ed Heaton <EdHeaton@WESTAT.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Ed Heaton <EdHeaton@WESTAT.COM>
Subject: Re: How to count the number of null value varibales in an observa
tion w/out specifying the variable names
Content-Type: text/plain
Shelton, Chang, et al;
You might want to simply use the _ALL_ list.
%let seed=123456;
data one;
array v[1:20] v1-v20;
Do j=1 to 10 ; Drop j ;
do _i_ = 1 to 20;
if ranuni(&seed.)< 0.1 then v[_i_] = .;
else v[_i_] = _i_;
end;
Output ;
End ;
run;
Data _null_ ;
Put _n_= @ ;
Set one ;
_n_ = nMiss( of _all_ ) ;
Put "Missing: " _n_ ;
Run ;
I used _n_ because it is not included in the _ALL_ list. Normally, I don't
like to change automatic variables; but _N_ gets automatically reset at the
top of the loop.
If you just want the numeric variables, code
Data _null_ ;
Put _n_= @ ;
Set one ;
_n_ = nMiss( of _numeric_ ) ;
Put "Missing: " _n_ ;
Run ;
Ed
Edward Heaton, SAS Senior Systems Analyst,
Westat (An Employee-Owned Research Corporation),
1600 Research Boulevard, RW-3541, Rockville, MD 20850-3195
Voice: (301) 610-4818 Fax: (301) 610-5128
mailto:EdHeaton@Westat.com http://www.Westat.com
-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of Chang
Y. Chung
Sent: Monday, December 06, 2004 10:13 AM
To: SAS-L@LISTSERV.UGA.EDU
Subject: Re: How to count the number of null value varibales in an
observation w/out specifying the variable names
On Mon, 6 Dec 2004 09:46:20 -0500, Shelton Zhong <xt_zhong@YAHOO.COM>
wrote:
>Suppose an observation has tens of variables, I certainly do not want
>to create an indicator varible for each of the variables nor to perform
>
>count_null = (v1=.) + (v2=.) + (v3=.) + .....
>
>because
>1) the v1, v2, v3, ... names are long
>2) there are tens of them
>3) they are dynamic (kept or dropped)
Hi,
In a data step, you can use the function nMiss() to count the number of
missing values, in the arguments. In order to get the list of variables, you
can use various forms of sas variable lists. Below is an example. HTH.
Cheers,
Chang
/* create an example dataset with one obs and 20 vars,
about 10 pct among which will have missing values */
%let seed=123456;
data one;
array v[1:20] v1-v20;
do _i_ = 1 to 20;
if ranuni(&seed.)< 0.1 then v[_i_] = .;
else v[_i_] = _i_;
end;
run;
/* count missing values */
data two;
set one;
array v[*] v1-v20;
nMiss = nMiss(of v1-v20);
put nMiss=;
run;
/* on log
nMiss=2
*/