Sample 46235: How to mimic the N function for character variables
The N function counts the number of non-missing values for numeric variables. We do not have a function that does that for character variables.
The example in the Full Code tab section counts the NON-missing character values.
CALL SYMPUTX has been available since the release of SAS® 9.0. The N function was introduced in SAS 9.1.3. CMISS and NMISS were introduced in SAS 9.2 to count missing values for character and numeric values across observations.
Note: Development is currently investigating the possibility of adding a new function to count non-missing character values.
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
This code runs stand alone to show how to count nonmissing 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 .
;
run;
proc contents data=temp out=mytemp;
run;
data _null_;
set mytemp nobs=total;
call symputx('totvar',total);
run;
data two;
set temp;
obs=&totvar;
miss=cmiss(of disp1-disp8);
nonmiss=&totvar-miss;
run;
proc print;
run;
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
This will count the nonmissing values for character values much like the N function does for numerics.
| Type: | Sample |
| Topic: | SAS Reference ==> DATA Step
|
| Date Modified: | 2012-05-08 09:51:27 |
| Date Created: | 2012-04-05 11:06:21 |
Operating System and Release Information
| SAS System | N/A | 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 | |
| Windows Vista for x64 | 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 | |