I can't get graphics to appear in the output file in SAS Viya with a relatively simple ODS HTML statement. This works fine in SAS 9.4, but doesn't work the same in SAS Viya.
ods html file='print.html' path="&_userhome" gpath="&_userhome";
proc print data=sashelp.class;
run;
proc sgplot data=sashelp.class;
scatter x=height y=weight;
run;
ods html close;
The output folder &_userhome exists. The output HTML file shows PROC PRINT output but not PROC SGPLOT output. How to fix?
Solution provided by SAS
ods html5 file="&_userhome./print2.html" options (bitmap_mode='inline');
proc print data=sashelp.class;
run;
proc sgplot data sashelp.class;
scatter x-height y=weight;
run;
ods html5 close;
What version of SAS Viya are you using? I ran this code in Viya 2025.01
ods html file='print.html' path="&_userhome" gpath="&_userhome";
proc print data=sashelp.class(obs=5);
run;
proc sgplot data=sashelp.class;
scatter x=height y=weight;
run;
ods html close;
and got the expected result:
The code also produced the expected results in Viya for Learners (LTS 2024.09).
No, that's not what I am asking about. You are looking at the results tab in Viya, whereas I am looking at the results in the output file named print.html opened in my web browser. In the results tab, I see the plot like you do, but it is not there in the print.html file.
Ah. OK. If you download the files and review the HTML, you can see that SAS hard-coded the path in the src=specification for the image. It does the same in Windows SAS. Try moving both files to a new location in Windows and you'll see the same effect. To work around this, you'd have to edit the HTML page to change the hardcoded path to this:
src="./SGPlot1.png"
Then, as long as you place both the HTML file and the .png file in the same folder, it will work as expected.
It sounds as if you are saying there is no way to write an ODS HTML command and have this work.
If that's true, this is very disappointing. In all my years of working in Base SAS, I have found it very helpful to write output including graphics to a particular folder with a specific file name, and keep everything together that way, all done via SAS code. If that isn't possible in Viya, this is a major hit to my normal workflow.
I await to hear from others if this is possible.
%let _userhome=c:\temp\z ; ods html body='print.html' path="&_userhome" gpath="&_userhome"; proc print data=sashelp.class; run; proc sgplot data=sashelp.class; scatter x=height y=weight; run; ods html close;
Also try HTML5 instead of HTML :
ods html5 body='print.html' path="&_userhome" gpath="&_userhome";
............
ods html5 close;
Thanks @Ksharp , but neither of these produce the desired plot in print.html using my SAS Viya.
Solution provided by SAS
ods html5 file="&_userhome./print2.html" options (bitmap_mode='inline');
proc print data=sashelp.class;
run;
proc sgplot data sashelp.class;
scatter x-height y=weight;
run;
ods html5 close;
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!