Date: Mon, 17 Nov 2008 17:14:28 -0500
Reply-To: "Howard Schreier <hs AT dc-sug DOT org>"
<schreier.junk.mail@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Howard Schreier <hs AT dc-sug DOT org>"
<schreier.junk.mail@GMAIL.COM>
Subject: Re: Any easier way to count these.
On Mon, 17 Nov 2008 14:21:39 -0600, ./ ADD NAME=Data _null_,
<iebupdte@GMAIL.COM> wrote:
>Dale's array solutions insures that you don't miss count when a target
>is embedded in a longer word. That can be accommodated with a small
>modification to your original code. You can achieve key stroke
>efficiency with a "SAS Variable List". I don't know how the methods
>compare using other efficiency measures.
>
>data have;
> infile cards missover;
> input (a1-a3)($);
> length concat $256;
> concat = cats(',',catx(',',of a:),',');
> bnd0 = count(concat,',bnd,');
> bnid0 = count(concat,',bnid,');
> total = sum(bnd0,bnid0);
> put (_all_)(=);
> *drop concat;
> cards;
>bnd bnid bnsr
>bnd bnd bnd
>bnid bnd
>bnid bnd bnidx
>;;;;
> run;
>proc print;
> run;
>
If there a lot (not just 2) literals to check, it makes sense to put them in
an array and accumulate TOTAL in a loop.
>On 11/17/08, Hari Nath <hari_s_nath@yahoo.com> wrote:
>> Thanks Dale and Akshaya for the array solution. Since i have several
>> variables, array seems to be more efficient than just using sas functions.
>>
>>
>> On Mon, 17 Nov 2008 11:08:55 -0800, Akshaya <akshaya.nathilvar@GMAIL.COM>
>> wrote:
>>
>> >There's a Lost card, so include missover option, to make all record
>> >read.
>> >
>> >Data have;
>> > infile cards missover;
>> > input (a1-a3) ($);
>> > cnt=0;
>> > array abc a1-a3;
>> > do over abc;
>> > if indexw(abc,'bnd') then cnt+1;
>> > if indexw(abc,'bnid') then cnt+1;
>> > end;
>> >cards ;
>> >bnd bnid bnsr
>> >bnd bnd bnd
>> >bnid bnd
>> >;
>> >
>> >Thanks!
>> >Akshaya
>>
|