LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (July 2006, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Fri, 21 Jul 2006 14:09:37 -0400
Reply-To:   Sigurd Hermansen <HERMANS1@WESTAT.COM>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   Sigurd Hermansen <HERMANS1@WESTAT.COM>
Subject:   Re: Count populated fields
Comments:   To: "Terjeson, Mark (IM&R)" <Mterjeson@russell.com>, sdlenter <sdlentert@AOL.COM>
In-Reply-To:   <16FD64291482A34F995D2AF14A5C932C015A6B87@MAIL002.prod.ds.russell.com>
Content-Type:   text/plain; charset="us-ascii"

Mark: For a more general method, consider replacing where Field1 ne '' with where Field1 is missing.

Aside from issues in V9+ related to comparisons of '' vs. ' ', the 'IS MISSING' comparison works equally well for numeric and character data types. Sig

-----Original Message----- From: owner-sas-l@listserv.uga.edu [mailto:owner-sas-l@listserv.uga.edu] On Behalf Of Terjeson, Mark (IM&R) Sent: Friday, July 21, 2006 2:00 PM To: sdlenter; SAS-L@LISTSERV.UGA.EDU Subject: RE: Count populated fields

Hi,

Here is one method:

data sample; Field1='Fred '; Field2=1; Field6=2; Field9=3; output; Field1='Fred '; Field2=1; Field6=.; Field9=3; output; Field1=' '; Field2=1; Field6=2; Field9=3; output; Field1='Fred '; Field2=.; Field6=2; Field9=3; output; Field1='Fred '; Field2=1; Field6=2; Field9=.; output; Field1='Fred '; Field2=1; Field6=2; Field9=3; output; Field1='Fred '; Field2=1; Field6=.; Field9=3; output; Field1=' '; Field2=1; Field6=.; Field9=3; output; Field1='Fred '; Field2=.; Field6=2; Field9=3; output; Field1='Barney'; Field2=1; Field6=2; Field9=.; output; Field1='Barney'; Field2=1; Field6=2; Field9=3; output; Field1='Barney'; Field2=1; Field6=2; Field9=3; output; Field1='Barney'; Field2=1; Field6=2; Field9=3; output; Field1='Barney'; Field2=1; Field6=2; Field9=3; output; Field1='Barney'; Field2=1; Field6=2; Field9=.; output; Field1='Barney'; Field2=1; Field6=2; Field9=.; output; Field1='Fred '; Field2=1; Field6=2; Field9=3; output; Field1='Barney'; Field2=1; Field6=.; Field9=3; output; Field1=' '; Field2=1; Field6=2; Field9=3; output; Field1='Barney'; Field2=.; Field6=2; Field9=3; output; Field1='Fred '; Field2=1; Field6=2; Field9=.; output; run;

* if Field1 is populated only, count the records ; proc sql; create table result1 as select Field1, count(*) as count from sample where Field1 ne '' group by Field1 ; quit;

* if Field2, Field6, and Field9 are populated ; * (those three only) - count the records ; proc sql; create table result2 as select Field1, count(*) as count from sample where Field2 ne . and Field6 ne . and Field9 ne . group by Field1 ; quit;

* if Field1 is populated only, count the records ; * AND if Field2, Field6, and Field9 are populated ; * (those three only) - count the records ; proc sql; create table result3 as select Field1, count(*) as count from sample where Field1 ne '' and Field2 ne . and Field6 ne . and Field9 ne . group by Field1 ; quit;

* or a PROCedure ; proc freq data=sample; table Field1 / list missing; where Field1 ne '' and Field2 ne . and Field6 ne . and Field9 ne .; run;

Hope this is helpful.

Mark Terjeson Senior Programmer Analyst, IM&R Russell Investment Group

Russell Global Leaders in Multi-Manager Investing

-----Original Message----- From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of sdlenter Sent: Friday, July 21, 2006 10:43 AM To: SAS-L@LISTSERV.UGA.EDU Subject: Count populated fields

how can I count populated fields for example if Field1 is populated only, count the records if Field2, Field6, and Field9 are populated (those three only) - count the records

Proc SQL is more desirable, but if you know how to do this in a data step - Please

Thanks


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