07-24-2012 02:11 AM
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!
Edit. I want to do such thing only using SAS, not using additional software if it is possible.
07-24-2012 10:26 AM
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. :-)
07-24-2012 11:03 AM
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
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.
07-24-2012 11:56 AM
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.
07-24-2012 02:11 PM
Hi: There were some previous forum postings (I know because I made some of them).
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
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.
02-11-2013 06:21 PM
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".
06-07-2017 02:50 PM
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
07-27-2017 11:30 AM
The notes Barry links to
have been recently updated.
I've turned most of the code into an R package available from CRAN or github, called "SASmarkdown".
11-30-2017 11:03 AM
A new version of the SASmarkdown package (0.4.3) is available on CRAN.
The ability to link code blocks is now automatically enabled. You just need to use the `collectcode=TRUE` chunk option to indicate code that needs to be used for later chunks.
In addition, there is now a `spinsas` function that generates Markdown and HTML files from marked up SAS command files. If the first draft of your document is a SAS command file with comments, it can be easiest to simply add a few bits of markup and process that.