On Mon, Feb 7, 2011 at 12:51 AM, Sid Sahgal <sahga...@gmail.com> wrote:
> Hello,
>     I am a new Lyx user. I want to include a latex file created by SAS ( a
> statistical software program). I follow the instructions on this website
> http://support.sas.com/rnd/base/ods/odsmarkup/latex.html.

Greetings

I've been doing a lot of stats work lately and I think I can suggest
an alternative that will be a bit better.

The Lyx insert-> listings menu creates a little box, where you can
paste output if you want. Turn on the view latex option  in lyx.
Insert a program listing object, note this is very customizable.  A
listings box has right click config, set the language to SAS. It may
be exactly what you need.  In the latex code box, you see what lyx is
doing,

\begin{lstlisting}[language=SAS]

The output format for listing boxes is easily customizable, of course,
and there are many pre-defined styles for various languages.  I don't
happen to find a pre-defined one that matches my needs, but I have
learned that the preamble can define your own style to look the way
you want.   You experiment with that, and then your next step can be
to save your sas in separate text files and then use LaTeX input
commands to bring the file into your document.  As you note this is
nicer than re-running and then cutting and pasting again from Excel.

Here's a document i made in that way

http://pj.freefaculty.org/ps909/terminal-2.pdf

I'm pasting in the whole preamble below.  I needed to have listings
appear as-if they were from Sweave, but in fact they are not.  This
just takes the Rstyle that Frank Harrell created at Vanderbilt and
then extracts the customized listings commands.
It creates 2 styles for listings, "Rstyle" and "Routstyle" and then in
the document, when a listing, you can just use the LyX
insert->listings, and if you have the "view latex source" turned on,
you see the code it uses is:


\begin{lstlisting}
vi newthing.txt # The old school editor, probably strictly black and white
\end{lstlisting}

Because my preamble uses "lstset" to put "Rstyle" as the default, this
gives output with the right listings. But you can easily change. You
can either type this in ERT or in the listings optional settings,
there is a last menu tab where you can type on the right side
"style=Routstyle", and the LaTeX markup ends up like this:

\begin{lstlisting}[style=Routstyle]
vi newthing.txt # The old school editor, probably strictly black and white
\end{lstlisting}

I DO NOT know the difference in meaning of "language" and "style" as
listings options, I've been doing this with styles, but as I inspect
what lyx does with the pull down menus (monitor the latex view,
again), I see it does language.

Now, how to input a separate file into a listing environment? The
manual for listings says you can do:

\lstinputlisting[language=SAS]{example.sas}

I just tested and found it accepts both options at the same time as well:

\lstinputlisting[language=SAS,style=Routstyle]{example.sas}

Oh, well.  I see this is difficult to describe.

I just decided to make you a working example:

http://pj.freefaculty.org/latex/smallExample.lyx

My example is a Beamer slide presentation, and there is a complication
that listings is not compatible with the default slide frame, so I
have to put those in in ERT. But if you download my example, I think
you can make it work.  Please note: Supply your own "example.sas" in
the working directory.

I hope this is my good deed for the day. Or I've not done too much damage.

pj

%%%%%%%That preamble, then %%%%%%%%%%%%%%

\usepackage{dcolumn}
\usepackage{booktabs}

% use 'handout' to produce handouts
%\documentclass[handout]{beamer}
\usepackage{wasysym}
\usepackage{pgfpages}
\newcommand{\vn}[1]{\mbox{{\it
#1}}}\newcommand{\vb}{\vspace{\baselineskip}}\newcommand{\vh}{\vspace{.5\baselineskip}}\newcommand{\vf}{\vspace{\fill}}\newcommand{\splus}{\textsf{S-PLUS}}\newcommand{\R}{\textsf{R}}


\usepackage{graphicx}
\usepackage{listings}

\mode<presentation>
{
  \usetheme{KU}
  \usecolortheme{dolphin} %dark blues
}

\usepackage{fancyvrb}
% In document Latex options:
\fvset{listparameters={\setlength{\topsep}{0em}}}
\def\Sweavesize{\normalsize}
\def\Rcolor{\color{black}}
\def\Rbackground{\color[gray]{0.95}}

\providecommand{\Rcolor}{\color[rgb]{0, 0.5, 0.5}}
\providecommand{\Routcolor}{\color[rgb]{0.461, 0.039, 0.102}}
\providecommand{\Rcommentcolor}{\color[rgb]{0.101, 0.043, 0.432}}

\providecommand{\Rbackground}{\color[gray]{0.91}}
\providecommand{\Routbackground}{\color[gray]{0.935}}
% Can specify \color[gray]{1} for white background or just \color{white}


\lstdefinestyle{Rstyle}{fancyvrb=false,escapechar=`,language=R,%
                        basicstyle={\Rcolor\Sweavesize},%
                        backgroundcolor=\Rbackground,%
                        showstringspaces=false,%
                        keywordstyle=\Rcolor,%
                        commentstyle={\Rcommentcolor\ttfamily\itshape},%

literate={<-}{{$\leftarrow$}}2{<<-}{{$\twoheadleftarrow$}}2{~}{{$\sim$}}1{<=}{{$\leq$}}2{>=}{{$\geq$}}2{^}{{$^{\scriptstyle\wedge}$}}1,%
                        alsoother={$},%
                        alsoletter={.<-},%

otherkeywords={!,!=,~,$,*,\&,\%/\%,\%*\%,\%\%,<-,<<-,/},%
                        escapeinside={(*}{*)}}%
% Other options of interest:
% frame=single,framerule=0.1pt,framesep=1pt,rulecolor=\color{blue},
% numbers=left,numberstyle=\tiny,stepnumber=1,numbersep=7pt,
% keywordstyle={\bf\Rcolor}

\lstdefinestyle{Routstyle}{fancyvrb=false,literate={~}{{$\sim$}}1{R^2}{{$R^{2}$}}2{^}{{$^{\scriptstyle\wedge}$}}1{R-squared}{{$R^{2}$}}2,%
 frame=single,framerule=0.2pt,framesep=1pt,basicstyle=\Routcolor\Sweavesize,%
 backgroundcolor=\Routbackground}


\lstnewenvironment{Sinput}{\lstset{style=Rstyle}}{}
\lstnewenvironment{Scode}{\lstset{style=Rstyle}}{}
\lstnewenvironment{Soutput}{\lstset{style=Routstyle}}{}

\lstset{tabsize=2, breaklines=true,style=Rstyle}


-- 
Paul E. Johnson
Professor, Political Science
1541 Lilac Lane, Room 504
University of Kansas

Reply via email to