[R] sas to r

Greg Adkison gadkison at email.wcu.edu
Sat Jul 17 00:18:10 CEST 2004

I would be incredibly grateful to anyone who'll help me translate some 
SAS code into R code.

Say for example that I have a dataset named "dat1" that includes five 
variables:  wshed, site, species, bda, and sla.  I can calculate with the 
following SAS code the mean, CV, se, and number of observations of 
"bda" and "sla" for each combination of "wshed," "species," and "site," 
restricting the species considered to only three of several species in 
dat1 (b, c, and p).  Moreover, I can output these calculations and 
grouping variables to a dataset named "dat2" that will reside in RAM 
and include the variables  wshed, site, species, mBdA, msla, cBda, 
sBdA, ssla, nBda, and nsla.

proc sort data=dat1;
  by wshed site species;
proc means data=dat1 noprint mean cv stderr n;
  by wshed site species;
  where species in ('b', 'c', 'p');
  var BdA sla;
  output out=dat2
    mean=mBdA msla
    cv=cBdA csla
    stderr=sBdA ssla
    n=nBdA nsla;


More information about the R-help mailing list