```Date: Tue, 7 Dec 2004 15:33:56 -0500 Reply-To: Nathaniel_Wooding@DOM.COM Sender: "SAS(r) Discussion" From: Nat Wooding Subject: Re: How to count the number of null value varibales in an observa tion w/out specifying the variable names Comments: To: Ed Heaton Content-type: text/plain; charset=US-ASCII Ed I don't think that your first solution with _all_ is valid here since if there are character variables, each will go through a character to numeric conversion and if they contain non-numeric symbols, they will be set to missing. Unless this would be valid for the particular application, the resulting variable with the missing count will be inflated by the number of "missing" character variables. The following example shows this data a; x = 1;y=.;z='three'; missing= nmiss(of _all_); proc print;run; Hence, I personally would use _numeric_. Also, your point of using _n_ is valid since in my example, missing = 3 (1 for y, 1 for z, and 1 for "missing" which is not filled until the function is evaluated). If the Chang wants to have the value as an output variable, a solution could be missing= nmiss(of _numeric_) - 1; Nat Wooding Ed Heaton cc: Sent by: "SAS(r) Subject: Re: How to count the number of null value varibales in an observa Discussion" tion w/out specifying the variable names 12/07/04 03:15 PM Please respond to Ed Heaton 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 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 */ ```

Back to: Top of message | Previous page | Main SAS-L page