Hi,
I have been working on a SAS VA report with a custom graph. Printing the report with the standard functionality "PDF Export" works but delivers terrible output. So I took the challenge to generate the pdf in a job (Job Execution) where I receive parameters from the report itself, subset the data and create a nice pdf-file, ready to be downloaded with a click. This all works. The only thing missing is an image of the custom graph.
So I have been studying the REST API's, very interesting. I am now able to generate an image of the graph but that's where it ends, and that's where my question starts..
This is a snippet of the code I use to create a job to capture an image of my custom graph.
filename jobresp temp; proc http method=POST url="&BASE_URI./reportImages/jobs" oauth_bearer=sas_services in="{ ""version"":3, ""reportUri"": ""&report_uri"", ""layoutType"": ""normal"", ""selectionType"": ""visualElements"", ""visualElementNames"": ""ve22789"", ""imageType"":""png"", ""size"": ""1200x800"", ""refresh"": true }" out=jobresp; headers "Accept"="application/vnd.sas.report.images.job+json" "Content-Type"="application/vnd.sas.report.images.job.request+json"; debug RESPONSE_BODY OUTPUT_TEXT; run;
After submitting the job I'm able to get the image with this code:
filename rsvg temp; proc http method=GET url="&BASE_URI./%trim(&image_uri)" out=rsvg oauth_bearer=sas_services; headers "Accept"="image/svg+xml"; run;
This all works. An svg-file is generated and I can view it in the browser but the image is not added in my pdf. This is where my questions begin:
FILENAME vaJason TEMP; /* FILENAME hdrout TEMP; */ PROC HTTP METHOD="GET" oauth_bearer=sas_services out=vaJason URL = "&BASE_URI/visualAnalytics/"; HEADERS "Accept" = "application/vnd.sas.api+json"; /* debug RESPONSE_BODY OUTPUT_TEXT; */ debug level=3; RUN; LIBNAME vaJason json;
This is a piece of the code I use to output to ODS PDF.
data _null_; a=pathname('work'); call symput('tt',strip(a)); run; filename f_pdf filesrvc parenturi="&SYS_JES_JOB_URI" name='_webstream.pdf' contenttype='application/pdf' contentdisp="attachment; test.pdf" ; ods pdf file=f_pdf; ods escapechar='^'; options nodate nonumber orientation=portrait; ods pdf text='^S={just=center font=("Verdana",8PT,Bold Italic)}Test pdf'; Title j=l "^{style[preimage=""&tt./test1.svg""]}"; proc print data=sashelp.cars(obs=3) noobs; run; ods pdf close;
A lot of this works but I cannot seem to add an image. And even when this works I still have another problem with all this. The datasources used are genereated in the Job Execution and stored in the CASUSER. When I developed the report the datasources were linked to casuser(dennis.remy@ilent.nl). I had to change this to casuser for others to be able to work with the report. But after changing this (what was very dificult because I was not able to do his under my own account, even though I created the report, I had to ask a collegae to change this), the http-call returns an error that the datasources are not accessible. So this, for now, only works with an old version of the report where the lib datasource is still casuser(dennis.remy@ilent.nl).
But thats another problem. I hope someone has the knowledge to help me with my first problem. Thanx a lot!
Unfortunately I don't have an answer for your primary questions/concern so hopefully someone more knowledgeable can chime in, but I am curious about the PDF that was originally generated from Visual Analytics. I don't want to derail this thread too much but is it something that we might be able to improve? How bad was the PDF? If you can detail what your custom graph contains I'd be interested in trying to reproduce and seeing if there is anything we can do from that aspect.
Hi Hunter,
Thanx for your effort. I have a track with SAS (CS0101854) open for these issues, but wanted to check the community as well.
The pdf generated from sas va is just something you dont have control over. Yes, there are a few setting you can apply when exporting but you dont seem to have any control over layout. fontsize etc. The main problem is that data which doesnt fit on a page is being clipped en put at the back of the report (a setting, but usually it is nessecary to have all the data presented). The first page is then repeated so very confusing for users. Second, the custom graph is being outputted with different axes (probably has something to do with data or no data, but I dont have any control over it). And this export is not even an export from the original report but an export of a COPY of the report in which some elements were tweaked and adjusted (margins etc) to look more pretty in the export. But having 2 reports also means twice the development/test effort when changes are applied. So exporting the original report even looks worse.
Attached some examples, these are not complete exports but some examples with elements, just to give you a hint.
I am curious about the code that is being send to the viya-server to generate these exports to pdf. I am able to make an image of the report with api-calls but the output is a SVG-file. This image is viewable in a browsers but when send to ODS PDF the procedure cannot find the image....Do you perhaps have samples of the code begin generated and send when using this standard print/export functionality in SAS VA?
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
See how to use one filter for multiple data sources by mapping your data from SAS’ Alexandria McCall.
Find more tutorials on the SAS Users YouTube channel.