[Tex/LaTex] Getting a frame with listings in beamer

beamerlistings

According to my experiments the listings package no longer allows

\begin{frame}[fragile]
  \begin{lstlisting}
       %CODE HERE
   \end{lstlisting}
\end{frame}

you can use

\begin{lstlisting}[frame = single]

to get a line around your frame and you can use title to get a title, but this does not produce the same effect as the regular frames.

Sample code:

\documentclass{beamer} {
  \mode<presentation> {
  \usetheme{Berkeley}
  % or ...

  %\setbeamercovered{transparent}
  % or whatever (possibly just delete it)
  \usecolortheme{albatross}
  \usecolortheme{sidebartab}
}

\usepackage{natbib}
\usepackage[english]{babel}
% or whatever

\usepackage[latin1]{inputenc}
% or whatever

\usepackage{array}

\usepackage{booktabs}
\setlength{\heavyrulewidth}{1.5pt}
\setlength{\abovetopsep}{4pt}

\usepackage{alltt}
\usepackage{times}

\usepackage[T1]{fontenc}
% Or whatever. Note that the encoding and the font should match. If T1
% does not look nice, try deleting the line with the fontenc.

\usepackage{listings}
\usepackage{multicol}
\usepackage{url}
\lstloadlanguages{SAS}
\lstset{language = SAS}


\setbeamercolor{navigation symbols}{fg = white, bg = white}
\setbeamercolor{sectionintoc}{fg = white}

\title[] % (optional, use only with long paper titles)
{Lies, damn lies and ... SAS to the rescue!}


\author{Peter L. Flom}
% - Use the \inst{?} command only if the authors have different
%   affiliation.

\institute[Peter Flom Consulting] % (optional, but mostly needed)
{Peter Flom Consulting}

\date[Short Occasion] % (optional)
{SESUG \\September, 2015}

\subject{Talks}
% This is only inserted into the PDF information catalog. Can be left
% out.

\AtBeginSubsection[] {
 \begin{frame}<beamer>
    \frametitle{Outline}
    \tableofcontents[currentsubsection]
  \end{frame}
 }


% If you wish to uncover everything in a step-wise fashion, uncomment
% the following command:

%\beamerdefaultoverlayspecification{<+->}


\begin{document}
\lstset{language = SAS}

  \section{Introduction}

           \begin{lstlisting}[frame = single, title={SAS code for means}]
             data means1;
             input x @@;
              datalines;
                210 291 921 922 102
              ;
              run;

              proc means data = means1;
               var x;
              run;
           \end{lstlisting}
\end{document} 

Is there a way to get "normal" looking frames with listings or should I use one of the verbatim packages?

EDIT June 3, 2015, 7PM Eastern

Per the comments, I tried a simpler version and still got the same error: "Runaway argument? File ended while scanning use of \next"

\documentclass{beamer} 

\usepackage{listings}
\lstset{language = SAS}

\title[] % (optional, use only with long paper titles)
{Lies, damn lies and ... SAS to the rescue!}


\author{Peter L. Flom}
% - Use the \inst{?} command only if the authors have different
%   affiliation.

\institute[Peter Flom Consulting] % (optional, but mostly needed)
{Peter Flom Consulting}

\date[Short Occasion] % (optional)
{SESUG \\September, 2015}


\begin{document}
\lstset{language = SAS}

\section{Introduction}

\begin{frame}[fragile]

           \begin{lstlisting}[frame = single, title={SAS code for means}]
             data means1;
             input x @@;
              datalines;
                210 291 921 922 102
              ;
              run;

              proc means data = means1;
               var x;
              run;
           \end{lstlisting}
  \end{frame}
\end{document} 

Best Answer

If you remove the spaces before \end{frame} it compiles.

According to the beamer manual section 12.9:

If you wish to use a {verbatim} environment in a frame, you have to add the option [fragile] to the {frame} environment. In this case, you really have to use the {frame} environment (not the \frame command) and the \end{frame} must be alone on a single line.

Related Question