Date: Fri, 3 Jun 2005 10:08:10 -0700
Reply-To: Dale McLerran <stringplayer_2@YAHOO.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Dale McLerran <stringplayer_2@YAHOO.COM>
Subject: Re: circular shift a matrix in SAS/IML
In-Reply-To: <1117783008.786335.30720@z14g2000cwz.googlegroups.com>
Content-Type: text/plain; charset=iso-8859-1
--- Arash <amahdian@GMAIL.COM> wrote:
> Is it possible to circular shift a matrix in SAS/IML?
> I mean:
>
> a = { -1 -2 , -3 0 , 1 2 };
> c=CIRCSHIFTROW(a,1);
>
>
> c = { -3 0 , 1 2 , -1 -2};
>
> or
> c=CIRCSHIFTCOLUMN(a,1);
>
>
> c = { -2 -1 , 0 -3 , 2 1 };
>
> Thanks
>
Arash,
Certainly, you can do a circular shift. There is not an
existing SAS function, but you could write a function to do so.
For the row circular shift, you have
c = a[2:nrow(a),] // a[1,];
while for the column circular shift, you have
c = a[,2,ncol(a)] || a[,1];
To make these into a function, all that you would need to do is
code
start circshift(row_col, a);
if upcase(row_col)='ROW' then
c = a[2:nrow(a),] // a[1,];
else if substr(upcase(row_col),1,3)='COL' then
c = a[,2:ncol(a)] || a[,1];
else do;
put "ERROR: UPCASE of the first function argument did not";
put " equate to 'ROW','COL', or 'COLUMN'";
c = J(nrow(a), ncol(a), .);
end;
return (c);
finish;
You can then invoke your function as
mat = circshift('row', mat);
or
mat = circshift('col', mat);
Dale
---------------------------------------
Dale McLerran
Fred Hutchinson Cancer Research Center
mailto: dmclerra@NO_SPAMfhcrc.org
Ph: (206) 667-2926
Fax: (206) 667-5977
---------------------------------------
__________________________________
Do you Yahoo!?
Yahoo! Mail - Find what you need with new enhanced search.
http://info.mail.yahoo.com/mail_250
|