# Re: [R] sas to r

Date: Sat 17 Jul 2004 - 09:10:48 EST

On Fri, 2004-07-16 at 23:18, Greg Adkison wrote:
> I would be incredibly grateful to anyone who'll help me translate some
> SAS code into R code.

Searching for "SAS code OR script OR translate" on http://maths.newcastle.edu.au/~rking/R/ gives a few results, one of which looks promising is
http://tolstoy.newcastle.edu.au/R/help/04/04/0009.html and http://tolstoy.newcastle.edu.au/R/help/04/02/0660.html

> 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.

Sepal.Length Sepal.Width Petal.Length Petal.Width Species

```1            5.1         3.5          1.4         0.2     setosa
2            4.9         3.0          1.4         0.2     setosa
...
51           7.0         3.2          4.7         1.4 versicolor
52           6.4         3.2          4.5         1.5 versicolor
...
101          6.3         3.3          6.0         2.5  virginica
102          5.8         2.7          5.1         1.9  virginica

```

> tapply(Sepal.Length, Species, function(x) c( mean(x), sd(x)/mean(x),
length(x) ))
\$setosa
[1] 5.00600000 0.07041344 50.00000000

\$versicolor
[1] 5.93600000 0.08695606 50.00000000

\$virginica
[1] 6.58800000 0.09652089 50.00000000

> 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;
>
> Thanks,
> Greg
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help