Date: Tue, 11 Jan 2011 16:19:22 -0500
Reply-To: Tom Abernathy <tom.abernathy@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Tom Abernathy <tom.abernathy@GMAIL.COM>
Subject: Re: Identify ties for values of variables
Why not just approach the problem directly and loop over all pairs and check
for matches. From the example results there appears to be an unspecified
requirement that matches for the value of zero do not count.
data flags;
set sample;
array b b1-b8;
flag=0;
do i=1 to dim(b) while (flag=0);
if b(i) then do j=i+1 to dim(b) while (flag=0);
if (b(i)=b(j)) then flag=1;
end;
end;
if flag then firstpair=cats('(',catx(',',i-1,j-1),')');
put (_all_) (=);
run;
b1=2 b2=0 b3=5 b4=6 b5=3 b6=0 b7=0 b8=0 flag=0 i=9 j=9 firstpair=
b1=3 b2=0 b3=4 b4=0 b5=0 b6=3 b7=2 b8=0 flag=1 i=2 j=7 firstpair=(1,6)
On Tue, 11 Jan 2011 12:31:27 -0800, Terjeson, Mark <Mterjeson@RUSSELL.COM>
wrote:
>Was pondering another looping design,
>so basically the code below does not
>even need the emptyarray.
>
>
>
>
>data sample;
> input b1 b2 b3 b4 b5 b6 b7 b8;
>cards;
>2 0 5 6 3 0 0 0 0
>3 0 4 0 0 3 2 0 1
>;
>run;
>
>data result(drop=i x:);
> array x{10} x1-x10;
> array b{8} b1-b8;
> retain rcdone 1;
> set sample;
> flag = 0;
> do i = 1 to 8;
> if b{i} ne 0 then
> do;
> if x{b{i}+1} then flag = 1;
> x{b{i}+1} = 1;
> end;
> end;
>run;
>
>
>
>Mark
>
>-----Original Message-----
>From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of
>Terjeson, Mark
>Sent: Tuesday, January 11, 2011 12:22 PM
>To: SAS-L@LISTSERV.UGA.EDU
>Subject: Re: Identify ties for values of variables
>
>Hi Shukla,
>
>Here is one of several approaches:
>
>The concept is to scan the digits
>and set an array if a digit is seen.
>By simply testing to see if that
>digit has already been set you can
>identify a colision. The empty dataset
>is used to quickly clear the temporary
>array so that you don't have to perform
>ten assignments to do the same thing.
>
>
>
>data sample;
> input b1 b2 b3 b4 b5 b6 b7 b8;
>cards;
>2 0 5 6 3 0 0 0 0
>3 0 4 0 0 3 2 0 1
>;
>run;
>
>
>data emptyarray;
> array x{10} x1-x10;
>run;
>
>
>data result(drop=i x:);
> array x{10} x1-x10;
> array b{8} b1-b8;
> retain rcdone 1;
> set sample;
> flag = 0;
> do i = 1 to 8;
> if b{i} ne 0 then
> do;
> if x{b{i}+1} then flag = 1;
> x{b{i}+1} = 1;
> end;
> end;
> set emptyarray point=rcdone;
>run;
>
>
>
>
>
>
>Hope this is helpful.
>
>
>Mark Terjeson
>Investment Business Intelligence
>Investment Management & Research
>Russell Investments
>206-505-2367
>
>
>Russell
>Global Leaders in Multi-Manager Investing
>
>
>
>
>
>
>-----Original Message-----
>From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of
>Shukla Kshirsagar
>Sent: Tuesday, January 11, 2011 11:40 AM
>To: SAS-L@LISTSERV.UGA.EDU
>Subject: Identify ties for values of variables
>
>I have 8 brands in a dataset, with possible values of 0-9 for each of
>them.
>
>I want to write macro code, where I can look for ties in the values of
>the
>brands, and create a flag.
>e.g if brand1=brand2 or brand1=3 or......brand1=brand8
> or brand2=brand3........
>then flag=1
>
>b1 b2 b3 b4 b5 b6 b7 b8 flag
>2 0 5 6 3 0 0 0 0
>3 0 4 0 0 3 2 0 1
>
>
>Thanks for your help,
>Shukla
|