How do we make the file downloadable once the submit button is pressed at the client side?. I'm creating a job definition in SAS Viya 3.5 and want the client to download a pdf or any other file format. Kind of new of new to stored process as well as its equivalent Jobs in SAS VIYA. Not sure if I am reading the job execution web application doc correctly.
filename f_pdf filesrvc parenturi="&SYS_JES_JOB_URI" name='Class.pdf' contenttype='application/pdf'; ods pdf file=f_pdf style=&_ODSSTYLE;
proc print data=xxxxx;
run;
ods pdf close;
The above code saves it but does not download into the downloads folder at the client site. How can we achieve that?
Thanks in advance!
Hi @jins - you were close! Here are the things I changed to make your code work:
And here is a functional program you can run in SAS Studio to reproduce (just open the link in the log at the end):
/* compile sasjs core macros */
filename mc url "https://raw.githubusercontent.com/sasjs/core/main/all.sas";
%inc mc;
/* set up the sas program */
filename ft15f001 temp lrecl=1000;
parmcards4;
filename f_pdf filesrvc parenturi="&SYS_JES_JOB_URI"
name='_webout.pdf'
contenttype='application/pdf'
contentdisp="attachment; filename=my.pdf";
ods pdf file=f_pdf /*style=&_ODSSTYLE */;
proc print data=sashelp.class;
run;
ods pdf close;
;;;;
/* create the job in SAS Drive */
%mx_createwebservice(path=/Public/app/demo,name=sendpdf)
For reference there are a bunch of examples for streaming files from Viya (or SAS 9, or SASjs server) in this macro: https://core.sasjs.io/mp__streamfile_8sas_source.html
There's no PDF option yet, but feel free to raise an issue or PR!
Hi @jins - you were close! Here are the things I changed to make your code work:
And here is a functional program you can run in SAS Studio to reproduce (just open the link in the log at the end):
/* compile sasjs core macros */
filename mc url "https://raw.githubusercontent.com/sasjs/core/main/all.sas";
%inc mc;
/* set up the sas program */
filename ft15f001 temp lrecl=1000;
parmcards4;
filename f_pdf filesrvc parenturi="&SYS_JES_JOB_URI"
name='_webout.pdf'
contenttype='application/pdf'
contentdisp="attachment; filename=my.pdf";
ods pdf file=f_pdf /*style=&_ODSSTYLE */;
proc print data=sashelp.class;
run;
ods pdf close;
;;;;
/* create the job in SAS Drive */
%mx_createwebservice(path=/Public/app/demo,name=sendpdf)
For reference there are a bunch of examples for streaming files from Viya (or SAS 9, or SASjs server) in this macro: https://core.sasjs.io/mp__streamfile_8sas_source.html
There's no PDF option yet, but feel free to raise an issue or PR!
thanks for this.
I had one more question - if the report link has to be shared, where should one store the job definition and the associated data sets. Currently it is under Users/Username... and this gives unable to read the Job definition error, if someone else tries to open it. This might be permission issue on my folder but where can this be moved to?
Thanks in advance.
That's really up to you and your site policies. You can put it anywhere in SAS Drive you like, just set any relevant permissions.
Hi @AllanBowe ,
Trying to use this code as sample, what does this part of the code do:
filename ft15f001 temp lrecl=1000;
parmcards4;
Hi @jimbobob - great question!
The strange looking filename is a special destination that - when used in combination with the parmcards statement - allows you to write arbitrary content to a fileref (in a very similar way to cards / datalines to a data set)
We use it in SASjs as a convenient way to deploy multiple stored processes in a single SAS program.
Ok very interesting, thanks for update
This is fascinating, so you code creates a job, so now all i need to do is associate the created job to a form right?
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 16. 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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: