Search code examples
latexsassas-ods

SAS: Custom ODS LATEX tagset


I'm trying to customize the output from SAS for the tagsets.latex, tagsets.simpleLatex and tagsets.tablesOnlyLatex tagsets. I nearly have what I want: only the data rows, no headers, no other tags at all.

This is the output I'm getting:

\tabularnewline
\tabularnewline
Internet    & 1    & 1    & 150.00    & 150.00    & .    & 150.00    & 150.00   \tabularnewline
Mobile    & 1    & 1    & 200.00    & 200.00    & .    & 200.00    & 200.00   \tabularnewline
Phone    & 1    & 1    & 100.00    & 100.00    & .    & 100.00    & 100.00   \tabularnewline

This is the output I want:

Internet    & 1    & 1    & 150.00    & 150.00    & .    & 150.00    & 150.00   \tabularnewline
Mobile    & 1    & 1    & 200.00    & 200.00    & .    & 200.00    & 200.00   \tabularnewline
Phone    & 1    & 1    & 100.00    & 100.00    & .    & 100.00    & 100.00   \tabularnewline

This is how to create the sample tagset:

*Running this creates a new template;
Proc template;
    define tagset Tagsets.minimal;
    define event byline;end;
    define event proc_title;end;
    define event note;end;
    define event Error;end;
    define event Warn;end;
    define event Fatal;end;
    define event system_footer;end;
    define event leaf;end;
    define event proc_branch;end;
    define event branch;end;
    define event pagebreak;end;
    define event system_title;end;
    define event table;end;
    define event table_head;end;
    define event colspecs;end;
    define event colspec_entry;end;
    define event row;
            break /if ^contains( $HTMLCLASS, "data");
            put "                " NL "  " /if ^exists( $colspan);
        finish:     
            break /if cmp( $sascaption, "true");
            break /if contains( HTMLCLASS, "data");
            put "\tabularnewline" NL /if ^exists( $colspan);
    end;

    define event data;
        start:
            put VALUE /if cmp( $sascaption, "true");

            break /if cmp( $sascaption, "true");
            break /if ^contains( HTMLCLASS, "data");
            break /if exists( $colspan) | exists ( $cell_align );

            put %nrstr(" & ") /if ^cmp( COLSTART, "1");

            unset $colspan;
            set $colspan colspan;     

            put tranwrd(VALUE,"-","$-$") /if contains( HTMLCLASS, "data");
            put VALUE /if ^contains( HTMLCLASS, "data");
            put "   ";

        finish:
            break /if ^contains( HTMLCLASS, "data");
            break /if cmp( $sascaption, "true");
            break /if exists( $colspan) | exists ( $cell_align );
    end;

    parent = tagsets.simplelatex;
    end;
quit;

This creates some sample data:

data have;
   input stake bet_channel $;
   datalines; 
150 Internet  
200 Mobile 
100 Phone 
run;
 PROC PRINT data=have; RUN;

 ods tagsets.minimal file='C:\Temp\betChannel_data.tex' (notop nobot) newfile=table;
proc means data = have N MEAN MEDIAN STDDEV MIN MAX MAXDEC=2;
        VAR stake;
        label bet_channel = "Channel";
        CLASS bet_channel;
run;
ods tagsets.minimal close;    
x 'notepad C:\Temp\betChannel_data.tex';

I'm very close to the solution as I've managed to cull all the rest of the tags from the code and format the rest of it as needed. I just need a way of skipping the '\tabularnewline' if the line is empty, for example. The problem is in this method of the template, I think.

define event row;
        break /if ^contains( $HTMLCLASS, "data");
        put "                " NL "  " /if ^exists( $colspan);
    finish:     
        break /if cmp( $sascaption, "true");
        break /if contains( HTMLCLASS, "data");
        put "\tabularnewline" NL /if ^exists( $colspan);
end;

I'd appreciate any help at all. Thanks.


Solution

  • Set a variable in the data event when data exists, then check for that in the row event. I use $hasdata here.

    So in row:

    finish:     
        break /if cmp( $sascaption, "true");
        break /if contains( HTMLCLASS, "data");
        break /if ^exists($hasdata);
        put "\tabularnewline" NL /if ^exists( $colspan);
        unset $hasdata;
    

    And in data:

       unset $colspan;
       set $colspan colspan;     
       set $hasdata '1';