SAS:自定义ODS LATEX标记集

时间:2013-07-17 13:35:20

标签: latex sas sas-ods

我正在尝试为tagsets.latex,tagsets.simpleLatex和tagsets.tablesOnlyLatex标记集自定义SAS的输出。我几乎拥有我想要的东西:只有数据行,没有标题,没有其他标记。

这是我得到的输出:

\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

这是我想要的输出:

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

这是创建示例标记集的方法:

*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;

这会创建一些示例数据:

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';

我非常接近解决方案,因为我已经设法从代码中剔除其余所有标签,并根据需要格式化其余部分。例如,如果该行为空,我只需要一种跳过'\ tabularnewline'的方法。问题在于模板的这种方法,我认为。

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;

我会感激任何帮助。 感谢。

1 个答案:

答案 0 :(得分:1)

在数据存在时在数据事件中设置变量,然后在行事件中检查该变量。我在这里使用$hasdata

所以在行中:

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

在数据中:

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