Date: Thu, 8 Oct 2009 18:21:15 -0700
Reply-To: BruceBrad <b.bradbury@UNSW.EDU.AU>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: BruceBrad <b.bradbury@UNSW.EDU.AU>
Organization: http://groups.google.com
Subject: Re: Matrix operations on proc reg output
Content-Type: text/plain; charset=ISO-8859-1
Thanks Dale
Very useful, I'll try this. I'm sure I would have had great difficulty
working out how to do this without your neat example. I've now got
this working for a simple dummy test file.
I need to read from two datasets within the do loop. Will the program
run faster if I put the Use statements outside the loop and use Setin
statements inside the loop?
Thanks
Bruce.
> proc iml;
> use test;
> read all var{"site"} into by_vars;
> index = 1:nrow(by_vars);
> byvar_begin = uniqueby(by_vars, 1, index);
> Nsites = nrow(byvar_begin);
> byvar_end = byvar_begin[2:Nsites]-1 // nrow(by_vars);
> print byvar_begin byvar_end;
>
> byvar_ybar = J(Nsites,3,0);
> do i=1 to Nsites;
> firstobs = byvar_begin[i];
> lastobs = byvar_end[i];
> read point(firstobs:lastobs) var{"y"} into y;
> nobs = nrow(y);
> ybar = y[:,];
> site = by_vars[firstobs];
> byvar_ybar[i,] = site || nobs || ybar;
> end;
> print byvar_ybar;
> quit;
>
|