BookmarkSubscribeRSS Feed
BERENZ
Calcite | Level 5

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.

10 REPLIES 10
chang_y_chung_hotmail_com
Obsidian | Level 7

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. 🙂

BERENZ
Calcite | Level 5

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

chang_y_chung_hotmail_com
Obsidian | Level 7

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

Cynthia_sas
SAS Super FREQ

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

BERENZ
Calcite | Level 5

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.

Cynthia_sas
SAS Super FREQ

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

kmcital
Calcite | Level 5

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".

BarryDeCicco
Obsidian | Level 7

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   

Doug_Hemken
Calcite | Level 5

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".

Doug_Hemken
Calcite | Level 5

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.

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 10 replies
  • 11568 views
  • 7 likes
  • 6 in conversation