![]() | ![]() | ![]() | ![]() | ![]() |
The new CMISS function in SAS 9.2 makes it much easier to count missing values on each observation of a SAS dataset. Prior to this, you needed to use multiple lines of code to accomplish what a single line does in 9.2 and above.
The basic syntax is:
newvariable=cmiss(argument1, argument2,...);
Below is information from the SAS 9.2 OnlineDoc.
Details A character expression is counted as missing if it evaluates to a string that contains all blanks or has a length of zero. A numeric expression is counted as missing if it evaluates to a numeric missing value: ., ._, .A, ... , .Z. Comparisons The CMISS function does not convert any argument. The NMISS function converts all arguments to numeric values.
Note: The NMISS function was introduced in SAS 8.0. The only time that NMISS converts an argument to numeric is if it looks like a number. Alphabetic characters will generate an error.
The Full Code tab and Results/Output tab contain sample programs and the output they produce.
| Product Family | Product | System | SAS Release | |
| Reported | Fixed* | |||
| SAS System | Base SAS | z/OS | 9.2 TS1M0 | |
| Microsoft® Windows® for 64-Bit Itanium-based Systems | 9.2 TS1M0 | |||
| Microsoft Windows Server 2003 Datacenter 64-bit Edition | 9.2 TS1M0 | |||
| Microsoft Windows Server 2003 Enterprise 64-bit Edition | 9.2 TS1M0 | |||
| Microsoft Windows XP 64-bit Edition | 9.2 TS1M0 | |||
| Microsoft® Windows® for x64 | 9.2 TS1M0 | |||
| Microsoft Windows Server 2003 Datacenter Edition | 9.2 TS1M0 | |||
| Microsoft Windows Server 2003 Enterprise Edition | 9.2 TS1M0 | |||
| Microsoft Windows Server 2003 Standard Edition | 9.2 TS1M0 | |||
| Microsoft Windows XP Professional | 9.2 TS1M0 | |||
| Windows Vista | 9.2 TS1M0 | |||
| 64-bit Enabled AIX | 9.2 TS1M0 | |||
| 64-bit Enabled HP-UX | 9.2 TS1M0 | |||
| 64-bit Enabled Solaris | 9.2 TS1M0 | |||
| HP-UX IPF | 9.2 TS1M0 | |||
| Linux | 9.2 TS1M0 | |||
| Linux for x64 | 9.2 TS1M0 | |||
| OpenVMS on HP Integrity | 9.2 TS1M0 | |||
| Solaris for x64 | 9.2 TS1M0 | |||
/* create sample data and use the function */
options nocenter;
data one;
set sashelp.class;
if age gt 14 then age = .;
if height lt 59 then height = .;
if weight lt 90 then weight = .;
if index(name,'a') gt 0 then name = ' ';
howmanymiss=cmiss(name,age,height,weight);
run;
proc print;
run;
If you have a lot of variables, this next example shows how to count the
missing values using an ARRAY and the CMISS function.
data temp;
input (disp1-disp8) ($);
datalines;
1 2 . 4 5 6 7 8
. 2 3 4 5 . 7 8
1 2 3 4 5 6 7 8
1 2 3 . . 6 . 8
1 2 3 4 5 6 7 8
1 . 3 . 5 . 7 .
;
data countmissing;
set temp;
array vars(8) $ disp1-disp8;
missing=0;
do i = 1 to 8;
if vars(i)=' ' then missing+1;
end;
/* Using CMISS, only one statement needed rather than 5: */
c_miss_missing = cmiss(of vars[*]);
drop i;
run;
proc print;
run;
Prior to creation of these functions, the following code did the same thing.
/* count missing character values */
data temp;
input (disp1-disp8) ($);
datalines;
1 2 . 4 5 6 7 8
. 2 3 4 5 . 7 8
1 2 3 4 5 6 7 8
1 2 3 . . 6 . 8
1 2 3 4 5 6 7 8
1 . 3 . 5 . 7 .
;
data countmissing;
set temp;
array vars(8) disp1-disp8;
missing=0;
do i = 1 to 8;
if vars(i)=' ' then missing+1;
end;
drop i;
proc print;
run;
Output from the CMISS function. The SAS System 15:00 Wednesday, July 8, 2009 7 Obs Name Sex Age Height Weight howmanymiss 1 Alfred M 14 69.0 112.5 0 2 Alice F 13 . . 2 3 F 13 65.3 98.0 1 4 F 14 62.8 102.5 1 5 Henry M 14 63.5 102.5 0 6 M 12 . . 3 7 F 12 59.8 . 2 8 F . 62.5 112.5 2 9 Jeffrey M 13 62.5 . 1 10 John M 12 59.0 99.5 0 11 Joyce F 11 . . 2 12 Judy F 14 64.3 90.0 0 13 Louise F 12 . . 2 14 F . 66.5 112.0 2 15 Philip M . 72.0 150.0 1 16 Robert M 12 64.8 128.0 0 17 M . 67.0 133.0 2 18 M 11 . . 3 19 M . 66.5 112.0 2 Output from code used prior to SAS 9.2 The SAS System 14:30 Tuesday, July 7, 2009 19 Obs disp1 disp2 disp3 disp4 disp5 disp6 disp7 disp8 missing 1 1 2 4 5 6 7 8 1 2 2 3 4 5 7 8 2 3 1 2 3 4 5 6 7 8 0 4 1 2 3 6 8 3 5 1 2 3 4 5 6 7 8 0 6 1 3 5 7 4
| Type: | Usage Note |
| Priority: | |
| Topic: | SAS Reference ==> Functions ==> Functions |
| Date Modified: | 2010-08-02 15:33:09 |
| Date Created: | 2009-07-08 16:13:03 |





