The SAS Output Delivery System and reporting techniques

R Markdown equivalent in SAS

Reply
Occasional Contributor
Posts: 10

R Markdown equivalent in SAS

I wonder if there is a equivalent of R Markdown in SAS or how to do this in SAS? I want to have colored SAS code and its result below.

I want to prepare training materials for students and, as much I can, try to avoid copy and paste syntax into html (doc, pdf). There is option ods text and SASweave but it isn't what I want to do.

link to R Markdown: http://rstudio.org/docs/authoring/using_markdown

Looking forward for solutions to my problem!

MB

Edit. I want to do such thing only using SAS, not using additional software if it is possible.

Regular Contributor
Posts: 241

Re: R Markdown equivalent in SAS

You can re-direct both log and list outputs into a single text file and parse its lines. A simple example is easy to make as I have done back in 2001 (see my sas-l posting). But bullet-proofing it is almost impossible because it is just impossible to reliably parse sas log files. You also lose the syntax coloring -- because log file is a simple text. If you are interested, then let me know. I can send you the sas2html macro source -- I have to warn you, though, that it is using sas regular expressions -- it was written before perl reg ex was widely available in sas. :-)

Occasional Contributor
Posts: 10

Re: R Markdown equivalent in SAS

I'm interested in your sas macro Smiley Happy i would be grateful if you send me your proposition to solve my problem.

Regular Contributor
Posts: 241

Re: R Markdown equivalent in SAS

Send me an email. I will send the macro to you as an attachment. Thanks!!

SAS Super FREQ
Posts: 8,740

Re: R Markdown equivalent in SAS

Hi:

  There have been a couple of previous forum postings on capturing and color coding the log using ODS. In addition to other suggestions, take a look at this 2012 paper

http://support.sas.com/resources/papers/proceedings12/324-2012.pdf

by Warren Kuhfeld and Tim Arnold that discusses how to use LaTeX with an open source package called StatRep, which is similar to SASWeave, but not the same. For example, the entire paper with code snippets and output was written in StatRep.

cynthia

Occasional Contributor
Posts: 10

Re: R Markdown equivalent in SAS

Many thanks for this article! Maybe it's not exactly what I wanted but it will be helpful. I searched forum before i post my question but I didn't find anwser for my problem. Is there an example of ODS HTML which contains both colored SAS codes and results? I want to make webpage for students where they can have practical examples of how to use SAS (code + results) and I love R Markdown, it's so simple. Hope there is similar way to do the same thing in SAS.

SAS Super FREQ
Posts: 8,740

Re: R Markdown equivalent in SAS

Hi: There were some previous forum postings (I know because I made some of them).

https://communities.sas.com/message/40422#40422

https://communities.sas.com/message/42171#42171

https://communities.sas.com/message/16679#16679

For some of the older postings, the syntax in the programs got garbled a bit when the old posts got translated. So, for example,
_n_ could look like n or
_infile_ like infile

in the posting of the program code. And comments that should be

* this is a comment; end up looking like

  • this is a comment;

little bullet points without the asterisk.

But otherwise, the programs should be fairly readable but there will be a bit of fixup before you can submit the code.

I think that replicating the color coding from either the Enhanced Editor or the EG Editor will be hard to do. Essentially, you'd have to replicate the logic for the keywords for statements, the options, search the code for constants, quotes, etc, etc -- you'd be replicating the logic behind the SAS editor, but in your program.

I'd like to think that students, as students, will understand that the code they see above or below a program was what produced the results -- without the color coding. After all, when they look in the SAS documentation, the programs in the doc are "editor-neutral" -- folks on the mainframe don't always see color coding, folks on Unix using the VI editor won't see color coding, folks writing and submitting batch jobs won't see color coding -- so I think that showing them color coding is doing something above and beyond what they will see on the job when they have to look things up or read documentation or look at other people's programs on paper on in a text editor like Notepad or VI.

But, if you are organized about how you name your files, then it should be possible to "macrotize" the creation of output and the inclusion of code, especially into HTML files, since you can modify ODS HTML output files to allow output to be appended to an existing HTML file. (see this Tech Support note:

http://support.sas.com/kb/23/660.html) and notice that you have to use FIlENAME with the MOD option to append any subsequent output (like your program or your log to the created output.

cynthia

New User
Posts: 1

Re: R Markdown equivalent in SAS

Closest thing that I'm aware of is the R package knitr which has experimental support for SAS as an engine. The source is a .Rmd file that runs with a batch R job, knitr package will execute the SAS code chunks with SAS, render the .md file as well as .html if you want.  I haven't used it yet, but I have used R code chunks and it works great. Of course, this is what RStudio is doing when you click the button "Knit HTML".

Occasional Contributor
Posts: 15

Re: R Markdown equivalent in SAS

Here is a list of links I've compiled today, by coincidence.  I've read the first couple of links, and have gotten an example from the second link running on my computer.  The third link lists a variety of software which knitr can run.  Note that knitr is an R package, requiring R to run.  However R and RStudio (a great IDE  for R) are both free.  

 

SAS in knitr   

Frequent Learner
Posts: 1

Re: R Markdown equivalent in SAS

The notes Barry links to

http://www.ssc.wisc.edu/~hemken/SASworkshops/sas.html#writing-sas-documentation

have been recently updated.

 

I've turned most of the code into an R package available from CRAN or github, called "SASmarkdown".

Ask a Question
Discussion stats
  • 9 replies
  • 2313 views
  • 7 likes
  • 6 in conversation