首页 > 解决方案 > 如何在 SAS 中编写 ods 乳胶模板

问题描述

基于此文档:

https://support.sas.com/resources/papers/proceedings14/2033-2014.pdf

我创建了附加的结果并使用附加的代码,

在此处输入图像描述

但我想生成我自己的模板来创建输出(具有多行和部分网格的表):

在此处输入图像描述

有谁知道如何实现这一目标?或者是学习编写 ods 模板中使用的语言的好来源。非常感谢!

ods path(prepend) work.templat(update);

proc template;
 define tagset Tagsets.event1;
 define event colspec_entry;
 put just "|" /if ^cmp( just, "d");
 put "r|" /if cmp( just, "d");
 end;
 define event table;
 start:
 put NL;
 put NL;
 put "\begin{longtable}";
 finish:
 put "\hline \end{longtable}" NL;
 put NL;
 end;
 define event stacked_cell;
 start:
 put NL;
 put "\begin{tabular}";
 trigger alignment;
 finish:
 put "\end{tabular}" NL;
 end;
 define event colspecs;
 start:
 put "{";
 finish:
 put "}\hline" NL;
 end;
 define event colspec_entry;
 put just /if ^cmp( just, "d");
 put "r" /if cmp( just, "d");
 end;
 define event row;
 finish:
 put "\\" NL;
 end;
 define event header;
 start:
 trigger data;
 finish:
 trigger data;
 end;
 define event data;
 start:
 put VALUE /if cmp( $sascaption, "true");
 break /if cmp( $sascaption, "true");
 put %nrstr(" & ") /if ^cmp( COLSTART, "1");
 put " ";
 unset $colspan;
 set $colspan colspan;
 do /if exists( $colspan) | exists ( $cell_align );
 put "\multicolumn{";
 put colspan /if $colspan;
 put "1" /if ^$colspan;
 put "}{";
 put "|" /if ^$instacked;
 put just;
 put "|" /if ^$instacked;
 put "}{";
 done;
 put tranwrd(VALUE,"-","$-$") /if contains( HTMLCLASS, "data");
  put VALUE /if ^contains( HTMLCLASS, "data");
 finish:
 break /if cmp( $sascaption, "true");
 put "}" /if exists( $colspan) | exists ( $cell_align );
 end;
 define event rowspanfillsep;
 put %nrstr(" & ");
 end;
 define event rowspancolspanfill;
 put " ~";
 end;
 define event image;
 put "\includegraphics{";
 put BASENAME /if ^exists( NOBASE);
 put URL;
 put "}" NL;
 end;
 parent = tagsets.latex;
 end;
run;

data t;
length v1 $20;
input v1 $ v2;
datalines;
f=ma 21
sqrt(abd) 22
;
run;

ods tagsets.simplelatex file="/scratch/columbia/zz89/t1.tex";
proc print data=t;
run;
ods tagsets.simplelatex close;

ods tagsets.event1 file="/scratch/columbia/zz89/t2.tex";
proc print data=t;
run;
ods tagsets.event1 close;

data re1;
 infile "/scratch/columbia/zz89/t1.tex" pad missover;
 file "/scratch/columbia/zz89/t1_out.tex";
 length c1 $200;
 input c1 $ 1-200;
 p1=index(c1,'sqrt');
 if p1>0 then do;
 c2=substr(c1,(p1+5));
p2=index(c2,')');
 c3=substr(c1,1,(p1-1))||'$\sqrt{'||scan(c2,1,')') ||'}$'||substr(c2,(p2+1));
 put c3;
 end;
 else put c1;
run;

标签: saslatexods

解决方案


推荐阅读