[R] Converting SAS Code
MacQueen, Don
macqueen1 at llnl.gov
Fri Sep 29 22:43:52 CEST 2017
For the initial data step, assuming a data frame named stress already exists, and using base R, you can start with something like this:
barcodes.to.delete <- c('16187DD4015', '16187DD6002', {complete the comma-delimited vector of barcodes you don't want} )
yield <- subset(stress, !(barcode %in% barcodes.to.delete) )
yield <- subset(yield , !(field %in% c('YY','HB') )
## the above three lines could be done in a single line, but it would be long, ugly, hard to read, and hard to validate.
## easier to split it into a few steps
## another way, still using base R, and with a different syntax for the subsetting
records.to.drop <- stress$barcode %in% barcodes.to.delete | stress$yield %in% c('YY', 'HB')
yield <- stress[ !records.to.drop , ]
I think these are examples of doing it "the R way", not thinking in terms of directly translating SAS code to R code.
I used to use SAS a lot, but I don't know what the line
*Yield Champagin;
does.
--
Don MacQueen
Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062
Lab cell 925-724-7509
On 9/29/17, 5:47 AM, "R-help on behalf of Andrew Harmon" <r-help-bounces at r-project.org on behalf of andrewharmon42 at gmail.com> 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;
Can someone please help me convert my code to R? Any help would be much
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
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list