1

I'm using R Markdown to create a SAS proc sql tutorial but I have found several instances where code chunks with proc sql are not working as expected.

First, the outobs=N and inobs=N options will not evaluate and result in this error:

Error in engine(options) : Calls: <Anonymous> ... process_group.block -> call_block -> block_exec -> in_dir -> engine
In addition: Warning message: In system2(cmd, code, stdout=TRUE, stderr= TRUE, eng = options$engine.env): running command '"C:/Program Files/SASHome/SASFoundation/9.4/sas.exe" sas3afc64d1332b.sas -nosplash -ls 75' had status 1

Next, matching is not appearing to work in the proc sql code chunks. I have tried a subquery and a full join without success in R Markdown, while the same code works in base SAS.

Reproducible code:

require(knitr)
require(SASmarkdown)
saspath <- "C:/Program Files/SASHome/SASFoundation/9.4/sas.exe"
sasopts <- "-nosplash -ls 75"

/*filter with a subquery*/
data roster;
    input Person $;
    datalines;
    Tiffany 
    Tiffany 
    Barbara
    Henry 
    Carol
    Jane 
    Tiffany 
    Ronald 
    Thomas
    William
    William
    Henry 
    Carol
    Carol
    Ronald 
    Thomas
;

proc sql;
title "Subquery";
    select *
    from sashelp.class
    where Name in 
        (select distinct Person
        from roster);
quit;

proc sql;
title "Full join";
     select *
     from sashelp.class a full join roster b
     on a.Name = b.Person;
quit;

For the subquery above, the log results in R Markdown say that no rows were selected. The results from the full join are:

##            Name      Sex       Age    Height    Weight  Person
##            -----------------------------------------------------
##                                  .         .         .   Barbara
##                                  .         .         .   Carol  
##                                  .         .         .   Carol  
##                                  .         .         .   Carol  
##                                  .         .         .   Henry  
##                                  .         .         .   Henry  
##                                  .         .         .   Jane   
##                                  .         .         .   Ronald 
##                                  .         .         .   Ronald 
##                                  .         .         .   Thomas 
##                                  .         .         .   Thomas 
##                                  .         .         .   Tiffany
##                                  .         .         .   Tiffany
##                                  .         .         .   Tiffany
##                                  .         .         .   William
##                                  .         .         .   William
##            Alfred    M          14        69     112.5          
##            Alice     F          13      56.5        84          
##            Barbara   F          13      65.3        98          
##            Carol     F          14      62.8     102.5          
##            Henry     M          14      63.5     102.5          
##            James     M          12      57.3        83          
##            Jane      F          12      59.8      84.5          
##            Janet     F          15      62.5     112.5          
##            Jeffrey   M          13      62.5        84          
##            John      M          12        59      99.5          
##            Joyce     F          11      51.3      50.5          
##            Judy      F          14      64.3        90          
##            Louise    F          12      56.3        77          
##            Mary      F          15      66.5       112          
##            Philip    M          16        72       150          
##            Robert    M          12      64.8       128          
##            Ronald    M          15        67       133          
##            Thomas    M          11      57.5        85          
##            William   M          15      66.5       112

So it looks like proc sql is just not matching the Name/Person columns? I've tried the strip() function to be sure spaces are not the issue.

Again, if I run these code snippets in SAS, the subquery and join work without issue. Thanks in advance for any insight into why this code is not working as expected!

Leah
  • 11
  • 3
  • What happens if you run this in Jupyterlab instead of Rmarkdown? This would help determine if the source of the error is R or the markdown type structure. – Reeza Mar 27 '19 at 15:38

0 Answers0