[英]Embed SVG plot in SAS' HTML output file
我的印象是,在SAS 9.3中,可以在SVG輸出的 HTML輸出文件=> SAS頁面中嵌入SVG圖。
但是,在Linux服務器上嘗試以下簡單示例始終會生成帶有外部PNG文件的HTML文件。
ods listing close;
options device=svg;
ods graphics / outputfmt=svg reset=all;
ods html path="~" file="01_output.html";
proc sgplot data=sashelp.class;
scatter x=height y=weight;
ellipse x=height y=weight;
run;
ods html close;
ods listing;
有誰知道如何在SAS中將圖嵌入HTML?
您需要將reset=all
移到ODS GRAPHICS語句的開頭,或者將其刪除。 您將格式設置為SVG,然后將其重置。 當您的代碼生成PNG時,以下代碼在我的計算機(9.3 Windows)上運行。
ods listing close;
options device=svg;
ods graphics / outputfmt=svg;
ods html path="c:\temp\" file="01_output.html";
proc sgplot data=sashelp.class;
scatter x=height y=weight;
ellipse x=height y=weight;
run;
ods html close;
ods listing;
為了一步一步地完全嵌入HTML文件,您需要使用9.4並使用ods html5
,它會自動嵌入svg。 那里不需要options device=svg
。
編輯:以下內容僅適用於SAS 9.3和更低版本。 從v9.4開始,請參見上文Joe的選定答案。
是的,可以將SVG嵌入到.html文件中,但是不能使用ODS在單個步驟中完成。 ODS總是將SVG(或圖像)生成到一個單獨的文件中,然后再生成.html,您將需要自己對它們進行弗蘭肯斯坦(Frankenstein)。
關於使用SVG的這篇文章很長,但是很好:
http://css-tricks.com/using-svg/
這個問題也非常有用:
我是否對SVG文件使用<img>,<object>或<embed>?
這是一條膠帶示例(感謝Joe對其代碼進行了略微修改):
ods listing close;
options device=svg;
ods graphics / outputfmt=svg;
ods html path="%sysfunc(pathname(work))" file="whatever.html";
proc sgplot data=sashelp.class;
scatter x=height y=weight;
ellipse x=height y=weight;
run;
ods html close;
ods listing;
下面將創建一個名為embedded.html
的新HTML文件,其中包含一個非常准的.html文件。 它只是獲取SVG文件的內容並將其放在文件中間。
因為SVG實際上只是XML,所以現代瀏覽器應該可以很好地運行(但請參見上面的鏈接,了解如何在較舊的瀏覽器中運行該功能)。
data _null_;
file "%sysfunc(pathname(work))\embedded.html";
infile "%sysfunc(pathname(work))\SGPlot1.svg" end=eof;
if _n_ eq 1 then do;
put "<html><body>";
end;
input;
put _infile_;
if eof then do;
put "</body></html>";
end;
run;
您在評論中還提到您可能希望對其他類型的文檔(例如PDF / RTF)執行相同的操作。 如果是這樣,那么值得提出一個新的問題,因為您將必須在base64中對事物進行編碼才能實現這一點,而這並不是一件小事。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.