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

Duncan Murdoch murdoch.duncan at gmail.com
Tue Jul 13 16:03:26 CEST 2010


On 13/07/2010 8:39 AM, Roger Deangelis wrote:
> Thanks Richard and Erik,
>
> I hate to buy the book and not find the solution to the following:
>
> proc.means <- function(....) {
>    deparse(match.call()[-1])
> }
>
> proc.means(this is a sentence)
>
> unexpected symbol in   "proc means(this is) 
>
> One possible solution would be to 'peek' into the memory buffer that holds
> the
> function arguments. 
>
> It is easy to replicate the 'dataset' output for many SAS procs(ie
> transpose, freq, summary, means...)
> I am not interested in 'report writing in R'.
>
> The hard part is parsing the SAS syntax, I wish R had a drop down to PERL.
>
> per1 on;
>
>    some perl code
>
> perl off;
>   

It would not be hard to write something like that.  The syntax would be

perl("
    some perl code
")

where the function is something like

perl <- function(code) {
   f <- tempfile()
   writeLines(code, f)
   system(paste("perl", f))
}

You do need to watch out for escapes in the text, or be careful about 
what quotes you use, e.g.

 > perl('
+   print "Hello World\n";
+ ')
Hello World

Similarly for SAS, but I don't know how you tell SAS to process a file.

Duncan Murdoch

> also
>
> sas on;
>
>   some SAS code
>
> sas off;
>
> The purpose of parmbuff is to turn off of Rs scanning and resolution of
> function arguments
> and just provide the bare text between '('  and ')' in the function call.
>
> This is a very powerful construct.
>
> A function would provide something like
>
> sas.on(
>
>
> )
>
>



More information about the R-help mailing list