[R] SAS Proc summary/means as a R function

Roger Deangelis xlr82sas at gmail.com
Tue Jul 13 02:16:37 CEST 2010


Hi,

  I am new to R.

  I am trying to create an R function to do a SAS proc means/summary

          proc.means ( data=bsebal;
               class team year;
               var ab h; 
               output out=BseBalAvg mean=;
             run;)
           

I have a solution if I quote the the argument. The working code to produce
BseBalAvg
is very elegant.

normalize  <- melt(bsebal, id=c("team", "year"))                    #
normalize data
transpose <- cast(normalize, team + year ~ variable ,mean)   # team year h
ab (means) 

Here is the problem

In SAS we have the option parmbuff which puts all the 'macro arguments' text
into one string
ie

%macro procmeans(text)/parmbuff;
   %put &text;
%mend procmeans;

%procmeans(This is a sentence);

result
This is a sentence

Here is my R code

# This works
proc.means <- function(....) {
   sapply(match.call()[-1],deparse)
}
proc.means(thisisasentence)

Result
             .... 
"thisisasentence"

Note sapply allows for multiple arguments
and is not needed but is more robust.

# However this does not work

proc.means(this is a sentence)

unexpected symbol in   "proc means(this is)

It appears that the second space causes the error

I have had some luck using formulas  

# This works in spite of the spaces
proc.means <- function(formula) { 
    parmbuff <- deparse(substitute(formula)) 
    print(parmbuff)
}
proc.means(team + year + variable)

# this does not work - same issue as above
proc.means(team year variable)

unexpected symbol in   "proc means(team year)




                             
-- 
View this message in context: http://r.789695.n4.nabble.com/SAS-Proc-summary-means-as-a-R-function-tp2286888p2286888.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list