/*Scott-Knott in R and SAS (integration*/ *; /*Tutorial by: (Alysson Jalles) Consultoria: www.alyssonjallessite.wordpress.com*/ *; *I have the solution; *I've wrote a R/SAS routine for this purpose; *You can run R inside SAS to do it!; *To set SAS to run R codes follow my tutorial in: https://communities.sas.com/message/296841#296841; *Copy all of this message inside SAS to perform the analysis; *; *I'll provide an example with a SAS simulated dataset of a Randomized Complete Block Design (RCBD); *; *; *=======================================================================; *Simulating a RCBD experiment ===========================================BEGIN; *=======================================================================; *10 TREATMENTS; *3 REPLICATION; proc plan seed=123456; factors GEN=10 ordered REP=3 ordered/noprint; output out=RCBD_TEST /*GEN cvals=('GEN1' 'GEN2' 'GEN3' 'GEN4' 'GEN5' 'GEN6' 'GEN7' 'GEN8' 'GEN9' 'GEN10')*/ GEN nvals=(1 2 3 4 5 6 7 8 9 10) REP nvals=(1 2 3); run; *; *Simulating VARIABLES - BEGIN; data RCBD_TEST; set RCBD_TEST; call streaminit(8789); /*SEED= 8789*/ VAR1=rand('normal',110, 15); /*MEAN 110: STD: 15*/ run; data RCBD_TEST; set RCBD_TEST; call streaminit(907854); /*SEED= 907854*/ VAR2=rand('normal',3000, 751);run; /*MEAN 3000: STD: 751*/ *Simulating VARIABLES - END; *=======================================================================; *Simulating and RCBD experiment =====================================END; *=======================================================================; *; *Printing dataset, first 6 observations of simulated dataset:; proc print data=RCBD_TEST (obs=6); run; *; *; /*Scott-Knott statistic of VAR1 and VAR2 in R language*/ *Installing "ScottKnott" package in R; *ScottKnott in an R package to perform Scott-Knott analysis; *It will appear a windows, just click on the nearest mirror of your current place; * You just need to do it ONCE!; proc iml; title "Installing ScottKnott package in R (integration R with SAS)"; submit / R; #_______Begin of R code_________________ install.packages("ScottKnott") #_______End of R code_________________ endsubmit; *quit; *; *; *Installing "xlsx" package in R; *xlsx is a package to export Scott-Knott results in excel to your hard drive; *to use this package you have to install the ultimate version of java in your computer: https://www.java.com/pt_BR/download/ *It will appear a windows, just click on the nearest mirror of your current place; * You just need to do it ONCE!; proc iml; title "Installing xlsx package in R (integration R with SAS)"; submit/ R; #_______Begin of R code_________________ install.packages("xlsx") #_______End of R code_________________ endsubmit; *quit; *; *; *****SCOTT-KNOTT ANALYSIS BEGINS HERE..*******************************************************; *Changing treatments - GEN from numeric to factor type; *This is necessary; proc iml; title "Preparing variables (integration R with SAS)"; *Exporting SAS dataset to R environment; run ExportDataSetToR("WORK.RCBD_TEST", "RCBD_IN_R"); submit / R; #_______Begin of R code_________________ #Class of GEN and REP class(RCBD_IN_R$GEN) class(RCBD_IN_R$REP) #CONVERTING "GEN" and "REP" TO CHARACTER RCBD_IN_R$GEN<-as.character(RCBD_IN_R$GEN) RCBD_IN_R$REP<-as.character(RCBD_IN_R$REP) #Class of GEN and REP class(RCBD_IN_R$GEN) class(RCBD_IN_R$REP) #_______End of R code_________________ endsubmit; *quit; *; *; *; *Performing the Scott-Knott analysis; *We'll perform the analysis with 2 VARIABLES simultaneously, but you can extend this routine to N variables; title "Performing ScottKnott clustering in R (integration R with SAS) - by: Alysson Jalles"; submit / R; #_______Begin of R code_________________ require(ScottKnott) #Package to perform the SK analysis require(xlsx) #Package to perform the output in XLSX of results #For other kind of design as CRD, factorial, etc, consult the manual of R ScottKnott package #in: https://cran.r-project.org/web/packages/ScottKnott/ScottKnott.pdf #Applying univariate Scott-Knott clustering VAR1a <- SK(x=RCBD_IN_R, y=RCBD_IN_R$VAR1, model="y~GEN+REP", which="GEN", sig.level=0.05) #summary(VAR1a) VAR2a <- SK(x=RCBD_IN_R, y=RCBD_IN_R$VAR2, model="y~GEN+REP", which="GEN", sig.level=0.05) #summary(VAR2a) #Summary VAR1b<-(summary(VAR1a)) VAR2b<-(summary(VAR2a)) #_____________________________ #RENAMING MEANS TO THE NAME OF VARIABLE EVALUATED names(VAR1b)[names(VAR1b)=="Means"] <- "VAR1" names(VAR2b)[names(VAR2b)=="Means"] <- "VAR2" #RENAMING SK(5%)TO SK PLUS NAME OF VARIABLE EVALUATED names(VAR1b)[names(VAR1b)=="SK(5%)"] <- "SK_VAR1" names(VAR2b)[names(VAR2b)=="SK(5%)"] <- "SK_VAR2" #MERGING SCOTT-KNOTT RESULTS IN A SINGLE DATASET SK <-Reduce(function(x, y) merge(x, y, all=TRUE), list( VAR1b, #VAR1 VAR2b #VAR2 )) #RENAMING NAME OF VAR "Levels" TO GEN [TREATMENTS] names(SK)[names(SK)=="Levels"] <- "GEN" #_______End of R code_________________ endsubmit; *quit; *; *; *Exporting R results to your hard drive and SAS Environment; title "Exporting results to Windows hard drive and SAS Environment (integration R with SAS)"; title2 "Your file: 'Scott_Knott_output.xlsx' is in C:\ of your HD"; *Exporting results from R to SAS; run importdatasetfromR("WORK.SCOTT_KNOTT_SAS","SK"); submit / R; #_______Begin of R code_________________ write.xlsx(SK, "Scott_Knott_output.xlsx") #_______End of R code_________________ endsubmit; *quit; *; *; *Sorting treatments - GEN; proc sort; by GEN; run; *; *; *Printing results of Scott-Knott analysis in SAS (sig.level=0.05); Title "Scott-Knott Analysis results to RCBD design in SAS, by: Alysson Jalles"; proc print data=SCOTT_KNOTT_SAS noobs; run; *****SCOTT-KNOTT ANALYSIS ENDS HERE..*******************************************************; Thanks for read my material :smileygrin:...
... View more