1

我正在尝试为 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;

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

4

1 回答 1

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';
于 2013-07-17T14:14:43.680 回答