| Date: | Mon, 10 Sep 2007 15:11:23 -0500 |
| Reply-To: | "data _null_," <datanull@GMAIL.COM> |
| Sender: | "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU> |
| From: | "data _null_," <datanull@GMAIL.COM> |
| Subject: | Re: Equivalent of NMISS Function for Character Data? |
|
| In-Reply-To: | <456B52C41B724C41B96561D7AD283E7D6C76A2@mail.chpdm.umbc.edu> |
| Content-Type: | text/plain; charset=ISO-8859-1 |
Plus the CATX solution is considerably faster. But only when you crank
up the dimensions.
FF and FE are characters that are not likely to be found in data that
was typed at a keyboard.
data work.test;
array c[5000] $8;
do _n_ = 1 to 1e4;
call missing(of c[*]);
do i = 1 to dim(c);
if ranuni(12345) le .3 then c[i] = '12345678';
end;
output;
end;
drop i;
run;
data work.nMissC1;
set work.test;
array _c[*] c:;
nMissC = dim(_c) - count(catx('ff'x, of _c[*],'fe'x),'ff'x);
keep nmissc;
run;
data work.nMissC2;
set work.test;
array _c[*] c:;
do _n_ = 1 to dim(_c);
NMissC = Sum( NMissC , Missing(_C(_n_)));
end;
keep nmissc;
run;
proc compare base=work.nmissc1 compare=nmissc2;
run;
On 9/10/07, Jack Clark <JClark@chpdm.umbc.edu> wrote:
> Toby,
>
> Thanks for the example. I was pretty sure I knew what Richard was
> doing, it's just been a couple of years since working on a mainframe and
> hex data.
>
> I already had a solution where I was looping through the array elements:
>
> data eligcy06 (drop=j);
> merge elig06a (in=a) elig06b (in=b);
> by recipno;
> array grp(12) $ jan06grp feb06grp mar06grp apr06grp may06grp jun06grp
> jul06grp aug06grp sep06grp oct06grp nov06grp dec06grp;
> mmonths = 0;
> do j = 1 to 12;
> if grp(j) ne ' ' then mmonths + 1;
> end;
> run;
>
> Just for curiosity, I was asking about a solution that used a function,
> maybe taking care of the calculation in 1 line instead of the loop.
>
>
> Jack Clark
> Research Analyst
> Center for Health Program Development and Management
> University of Maryland, Baltimore County
>
>
> -----Original Message-----
> From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of
> toby dunn
> Sent: Monday, September 10, 2007 3:22 PM
> To: SAS-L@LISTSERV.UGA.EDU
> Subject: Re: Equivalent of NMISS Function for Character Data?
>
> Jack ,
>
> Perhaps this will be easier to understand.
>
> Data _Null_ ;
> Array C ( 10 ) $8 ( 'A' , '' , 'C' , '' , 'E' ,
> 'F' , 'G' , '' , 'I' , 'J' ) ;
>
> Do I = 1 To Dim( C ) ;
> NMissC = Sum( NMissC , Missing( C( I ) ) ) ;
> End ;
>
> Put NMissC= ;
>
> Run ;
>
>
>
>
> Toby Dunn
>
> Compromise is like telling a lie, it gets easier and easier. Each
> comprimise you make, that becomes your standard.
>
> Perfection doesnt exist, once you reach it, its not perfect anymore. It
> means something else.
>
>
>
>
>
> From: Jack Clark <JClark@CHPDM.UMBC.EDU>
> Reply-To: Jack Clark <JClark@CHPDM.UMBC.EDU>
> To: SAS-L@LISTSERV.UGA.EDU
> Subject: Re: Equivalent of NMISS Function for Character Data?
> Date: Mon, 10 Sep 2007 14:16:32 -0400
>
> Richard,
>
> Got it. Counting the number of elements in the array, separated by the
> hex 'ff'x.
>
> What role does the 'fe'x play? I think it is just a dummy element at
> the end so that the count equals the number of elements instead of the
> number of separators? Correct?
>
> Thanks.
>
> Jack Clark
> Research Analyst
> Center for Health Program Development and Management
> University of Maryland, Baltimore County
>
>
> -----Original Message-----
> From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of
> Richard A. DeVenezia
> Sent: Monday, September 10, 2007 1:47 PM
> To: SAS-L@LISTSERV.UGA.EDU
> Subject: Re: Equivalent of NMISS Function for Character Data?
>
> Jack Clark wrote:
> > Good morning,
> >
> > I have a character array of monthly Coverage Groups for Medicaid
> > patients:
> >
> > array grp(12) $ jan06grp feb06grp mar06grp apr06grp may06grp jun06grp
> > jul06grp aug06grp sep06grp oct06grp nov06grp
> dec06grp;
> >
> > I want to create a new variable MMONTHS which is a count of how many
> > months have a non-missing value. I know how to do this with IF-THEN
> > logic or using a DO Loop, but I got thinking about doing it with the
> > NMISS function - coming up with a nice one-line solution. Something
> > like:
> >
> > Mmonths =3D 12 - nmiss(of grp{*}));
> >
> > Problem is, it seems NMISS is only for numeric data. Is there an
> > equivalent function for character data, or could someone suggest an
> > alternative?
>
> ----------------------------------
> data foo;
> length nmissc 4;
> array c[10] $8
> ('A' 'B' 'C' 'D' 'E' 'F' 'G' 'H' 'I' 'J');
>
> do i = 0 to 9;
> nmissc = dim(c) - count(catx('ff'x, of c[*],'fe'x),'ff'x) ;
> put i= nmissc= ;
> c[i+1] = '';
> end;
> nmissc = dim(c) - count(catx('ff'x, of c[*],'fe'x),'ff'x) ;
> put i= nmissc= ;
> run;
> ----------------------------------
>
> Richard A. DeVenezia
> http://www.devenezia.com/
>
> _________________________________________________________________
> Get a FREE small business Web site and more from Microsoft(r) Office
> Live!
> http://clk.atdmt.com/MRT/go/aub0930003811mrt/direct/01/
>
|