# [R] Converting SAS Code

Tobias Fellinger tobby at htu.at
Fri Sep 29 15:43:41 CEST 2017

Hello,

in my experience the most direct path of converting SAS code to R is by
using dplyr. dplyr provides the filter function, the first part of your
code could look like this, assuming your datasets are stored as
data.frames:

library(dplyr)

yield <- filter(stress,
field != "YV",
field != "HV",
barcode != "16187DD4015",
barcode != "16187DD6002")

(and so on for the other barcodes.)

For mixed effects look into the lme4 package, lmer should use the reml
criterion per default, the model specifications work very different in
R. Look into the vingette [1] of the lme4 package chapter 2.1. gives an
explanation of the used model formulas.

You should get the coeficients of the fitted glmer model with the coef
function.

The Plots and univariate statistics work very different in R, have a
look at the functions group_by and summarise provided by the dplyr
package for calculating univariate statistics by groups, and the ggplot
2 package for plotting.

Tobi

[1] https://cran.r-project.org/web/packages/lme4/vignettes/lmer.pdf

On Fri, 2017-09-29 at 07:47 -0500, Andrew Harmon wrote:
> Hello all,
>
> My statistical analysis training up until this point has been entirely done
> in SAS. The code I frequently used was:
>
> *Yield Champagin;
>
> data yield;
>
> set stress;
>
> if field='YV' then delete;
>
> if field='HB' then delete;
>
> if barcode='16187DD4015' then delete;
>
> if barcode='16187DD6002' then delete;
>
> if barcode='16187DD2007' then delete;
>
> if barcode='16187DD5016' then delete;
>
> if barcode='16187DD8007' then delete;
>
> if barcode='16187DD7010' then delete;
>
> if barcode='16187DD7007' then delete;
>
> if barcode='16187DD8005' then delete;
>
> if barcode='16187DD6004' then delete;
>
> if barcode='16187DD5008' then delete;
>
> if barcode='16187DD7012' then delete;
>
> if barcode='16187DD6010' then delete;
>
> run; quit;
>
>
>
> Title'2016 Asilomar Stress Relief champagin yield';
>
> proc mixed method=reml data=yield;
>
> class rep Management Foliar_Fungicide Chemical_Treatment;
>
> model Grain_Yield__Mg_h_ =Management|Foliar_Fungicide|Chemical_Treatment
> Final_Stand__Plants_A_ / outpred=resids residual ddfm=kr;
>
> random rep rep*Management rep*Management*Foliar_Fungicide;
>
> lsmeans Management|Foliar_Fungicide|Chemical_Treatment / pdiff;
>
> ods output diffs=ppp lsmeans=means;
>
> ods listing exclude diffs lsmeans;
>
> run; quit;
>
> %include'C:\Users\harmon12\Desktop\pdmix800.sas';
>
> %pdmix800(ppp,means,alpha=0.10,sort=yes);
>
> ods graphics off;
>
> run; quit;
>
> proc univariate data=resids normal plot; id Barcode Grain_Yield__Mg_h_
> pearsonresid; var resid;
> proc print data=resids (obs=3);run;
>
> appreciated.
>
>
> Thanks,
>
>
> Andrew Harmon
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help