SAS Revenue Optimization Suite includes SAS ® Regular Price Optimization, which helps you establish and maintain optimal everyday prices; SAS ® Promotion Optimization, which enables you to make critical decisions concerning which promotions can maximize margin or minimize inventory levels; and SAS ® Markdown Optimization (on both SAS® Viya and SAS® 9.4), which helps you identify and implement. SAS Markdown Optimization enables retailers to proactively plan, optimize and execute. Pricing decisions for time-sensitive products. As part of the SAS Revenue Optimization Suite, the SAS solution deploys market-leading advanced analytics to help you devise data-driven markdown strategies. Higher profit margins and fresh inventory.
![Sas Markdown Sas Markdown](https://www.atorusresearch.com/wp-content/uploads/sas_highlight.004-1024x576.jpeg)
February 2020
- Including SAS Code in your Document
[SAS workshop notes] | SAS Markdown]
![Sas markdown Sas markdown](https://pp.userapi.com/c638123/v638123131/2395f/Qe5Yv3CWKLo.jpg)
Introduction
This is an introduction to using SASmarkdown (an R package) to produce documents based on SAS. (For installation instructions see The SASmarkdown package).
Using SASmarkdown in RStudio (or in R) gives you a method for writing simple documents which include the results of executing SAS commands. Both the document text and the source SAS code are in one file.
This is especially good for writing simple documents that explain statistical coding tasks. One way to think of this is as an extended and more readable version of writing comments in your source code. (It is also possible to turn SAS command files into documents, by including specially formatted comments, see Spinning SAS files.)
Sas Markdown Optimization
For an example of what a SASmarkdown document looks like, the source for this document is SASmarkdown.rmd
Background
Markdown is a language for formatting fairly simple documents using just a few text symbols. It is designed to be easy to read and write. You may already be using Markdown (in email, for instance) and not even realize it - it's that simple! If you are not already familiar with Markdown see John Gruber's Markdown article.
![Sas Sas](https://cdn.slidesharecdn.com/ss_thumbnails/draftsasandrandsasmay2018asameeting-180521234340-thumbnail-4.jpg?cb=1527086498)
R Markdown extends Markdown by allowing you to include blocks of code in one of several programming languages. The code is evaluated, and both the code and it's results are included in a Markdown document. To read more about the details of R Markdown see RStudio's R Markdown webpages
RStudio uses an R package called knitr
to render documents written in R Markdown. We will discuss some of the nuances of evaluating SAS code in subsequent articles.
The documentation for knitr
can be found in the book R Markdown: The Definitive Guide, in R's Help, or from this web page.
RStudio makes it easy to process your R Markdown document to produce a final HTML, pdf, or Word document. After you have written your R Markdown document, RStudio processes it with a simple click of a button! The focus in these articles will be on producing HTML (web) pages.
Some caveats:
Using SAS with R Markdown is not quite as graceful as using R with R Markdown, but the SASmarkdown package automates some techniques for putting together simple documents.
Note that this is not a friendly environment for extensively debugging problems in your SAS code (although with the right options you can see any SAS error messages in the SAS log file). If your code is at all complicated, you should work out the details in SAS first, then bring it into RStudio to develop your documentation!
Also note that some of the set up for using SAS and SASmarkdown is done in R. The basics are pretty simple, but to modify the default process it can help to be bilinugal in R and SAS.
Including SAS Code in your Document
SAS code is included in your R Markdown document in a block called a 'code chunk'. When you click on Rstudio's Knit button, your initial document (your 'source' document) is processed by the R function knitr
. This evaluates your code, collects the output, and produces a Markdown document. This Markdown document is then processed by a program called Pandoc to produce your final HTML document.
It helps to understand how knitr evaluates your SAS code. Knitr writes out your code into a file, and then submits that file to SAS to be run in batch mode. This produces SAS log and SAS 'listing' output. The listing output is then read back into knitr and used to produce a block of output in the Markdown document. (These files are ordinarily temporary.)
Limitations
There are several limitations that you will have to work with:
![Run Run](https://s3.manualzz.com/store/data/019865399_1-193249a4e9341c610b24d7f48962e40e.png)
Each code chunk runs separately as a SAS batch job, they are not processed as a single running session like R code. Interspersing text with executed code is not (quite) as simple as when running R code.
For example, suppose you have a DATA step early in your document, and then want to use that data in a later code chunk. In the later code chunk, SAS will have begun a new session (a new batch job) and 'forgotten' the first DATA step. SAS will not find the data, so SAS will send an error message to R Markdown. The default message R Markdown passes back to you will only tell you that SAS did not exit properly.
This difficulty is overcome with a chunk option automated through SASmarkdown,
collectcode
.Text (listing) output is simple to use. If you want to use SAS's HTML output instead of listing output, or if you want to include SAS graphics in your final document, a different SAS engine makes this fairly simple (
sashtml
).A third limitation is that
knitr
returns two blocks of text to your document - by default, the SAS code and the listing output. If you want to show your reader the content on the SAS log file, another SAS engine,saslog
makes this easy.
HTML or PDF Document?
You can choose between producing a final document as HTML or PDF when you click on the Knit button in RStudio.
![Markdown Markdown](https://bookdown.org/yihui/rmarkdown-cookbook/images/cover.png)
Longtime SAS users will find that SAS listing output looks as expected in both HTML and PDF documents. (Newer SAS users may not be familiar with listing output, since it is no longer the default when using SAS interactively. R Markdown runs SAS in batch mode, so listing output is produced by default.)
SAS HTML output can be included in a final HTML document, but renders poorly as a PDF document when run through R Markdown. To do much more than simply display listing output in PDF documents, you will want to investigate SAS's StatRep or Lenth's SASWeave.
Document Setup
An initial code chunk sets up the SAS engines for use in your document.
Code Chunk Setup
The code chunk setup to run SAS is not too difficult, either.
Running SAS
Here then, is a simple example as it might appear in your final document. The code chunk as written in your document is:
And appears in your document like this:
HTML Output and Graphics
There are two advantages to using SAS's HTML output, rather than the listing output. First, results tables become HTML tables instead of just monospaced text, and they will dynamically size themselves to the end user's window. Second, you can include SAS graphics in your final document with a minimum of fuss.
To use SAS's html output, use the sashtml
or sashtml5
engine, as described in a later article. An example as you would write it:
Run Sas Code In R
And as it appears in your document:
Sas Markdown Package
Simple Statistics | ||||||
---|---|---|---|---|---|---|
Variable | N | Mean | Std Dev | Sum | Minimum | Maximum |
Age | 19 | 13.31579 | 1.49267 | 253.00000 | 11.00000 | 16.00000 |
Height | 19 | 62.33684 | 5.12708 | 1184 | 51.30000 | 72.00000 |
Weight | 19 | 100.02632 | 22.77393 | 1901 | 50.50000 | 150.00000 |
Pearson Correlation Coefficients, N = 19 Prob > |r| under H0: Rho=0 | |||
---|---|---|---|
Age | Height | Weight | |
Age | <.0001 | 0.0003 | |
Height | <.0001 | <.0001 | |
Weight | 0.0003 | <.0001 |
Markdown Engine
Written using
Sas Revenue
- SASmarkdown version 0.5.2.
- knitr version 1.28.
- R version 3.6.2 (2019-12-12).
![](https://cdn-ak.f.st-hatena.com/images/fotolife/r/ruriatunifoefec/20200910/20200910011354.png)