I need to create a LaTeX table from SAS as follows.
1.8048 & -0.0799 & 0.3966 & -1.0833 & 2.2383 \\ -0.6242 & 0.5137 & -0.0866 & -0.5942 & 0.0319 \\ -0.7378 & -0.2501 & 0.6850 & -0.8042 & -0.7443 \\ -0.7955 & 0.3407 & -0.3005 & -1.3498 & 0.4327 \\ 1.3057 & 1.4251 & -0.4158 & 1.6144 & -1.0577 \\
I am going to pass these numbers to LaTeX using
\begin{tabular}{ccccc} \input{numbersfromsas} \end{tabular}
So I tried the following in SAS.
/*proc iml;*/
/*have=rannor(j(5,5,1));*/
/*mattrib have format=8.4;*/
/*create have from have;*/
/*append from have;*/
/*quit;*/
proc export dbms=dlm replace file="!userprofile\desktop\table.tex";
putnames=no;
delimiter="&";
run;
and this code creates the following outcome.
1.8048&-0.0799&0.3966&-1.0833&2.2383 -0.6242&0.5137&-0.0866&-0.5942&0.0319 -0.7378&-0.2501&0.6850&-0.8042&-0.7443 -0.7955&0.3407&-0.3005&-1.3498&0.4327 1.3057&1.4251&-0.4158&1.6144&-1.0577
(1) Can I put the "\\" at the end of each line as a linebreaker?
(2) Can I put the "(tab)&(tab)" rather than just the "&" as a delimiter? Thanks.
You might need to write out this layout yourself. Something like:
data _null_;
A=1; B=2; C=3;
file "%sysfunc(pathname(WORK))\t" dlm='09'x;
put A '&' B '&' C '\\';
run;
data CHECK;
infile "%sysfunc(pathname(WORK))\t" ;
input;
putlog '==>' _infile_ $hex36.;
run;
==>
31092632092633095C5C
Using ods latex sounds like a good idea. Have you tried it?
Thanks, but I do not consider ODS LATEX since the numbers must be customized a lot for the tables. For example, I sometimes apply formats in tables not vertically but horizontally—10 estimates horizontally and their test statistics.
You might need to write out this layout yourself. Something like:
data _null_;
A=1; B=2; C=3;
file "%sysfunc(pathname(WORK))\t" dlm='09'x;
put A '&' B '&' C '\\';
run;
data CHECK;
infile "%sysfunc(pathname(WORK))\t" ;
input;
putlog '==>' _infile_ $hex36.;
run;
==>
31092632092633095C5C
Or:
data _null_;
A=1; B=2; C=3; _='&';
file "%sysfunc(pathname(WORK))\t" dlm='09'x;
put A _ B _ C '\\';
run;
data T;
infile "%sysfunc(pathname(WORK))\t" ;
input;
putlog '==>' _infile_ $hex36.;
run;
==>310926093209260933095C5C
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.