How to write ods latex template in SAS

Sasadomo Source

Based on this document:

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

I created the attached result and using the attached code,

enter image description here

but I want to produce my own template that creates output as this (tables with multi-rows and partial grids):

enter image description here

Does anyone know how to achieve this? Or a good source to learn writing the language used in ods template. Much thanks!

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

Answers

comments powered by Disqus