BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
jins
Fluorite | Level 6

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!

 

1 ACCEPTED SOLUTION

Accepted Solutions
AllanBowe
Barite | Level 11

Hi @jins - you were close!  Here are the things I changed to make your code work:

 

  •  Changed the name to _webout.pdf - this is necessary for the result to stream
  • Added the contentdisp attribute - this is necessary for the file to auto-download
  • Removed the _odsstyle variable (not available in my 3.5 environment)

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!

/Allan
SAS Challenges - SASensei
MacroCore library for app developers
SAS networking events (BeLux, Germany, UK&I)

Data Workflows, Data Contracts, Data Lineage, Drag & drop excel EUCs to SAS 9 & Viya - Data Controller
DevOps and AppDev on SAS 9 / Viya / Base SAS - SASjs

View solution in original post

9 REPLIES 9
AllanBowe
Barite | Level 11

Hi @jins - you were close!  Here are the things I changed to make your code work:

 

  •  Changed the name to _webout.pdf - this is necessary for the result to stream
  • Added the contentdisp attribute - this is necessary for the file to auto-download
  • Removed the _odsstyle variable (not available in my 3.5 environment)

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!

/Allan
SAS Challenges - SASensei
MacroCore library for app developers
SAS networking events (BeLux, Germany, UK&I)

Data Workflows, Data Contracts, Data Lineage, Drag & drop excel EUCs to SAS 9 & Viya - Data Controller
DevOps and AppDev on SAS 9 / Viya / Base SAS - SASjs
jins
Fluorite | Level 6

thanks for this.

jins
Fluorite | Level 6

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.

AllanBowe
Barite | Level 11

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.

/Allan
SAS Challenges - SASensei
MacroCore library for app developers
SAS networking events (BeLux, Germany, UK&I)

Data Workflows, Data Contracts, Data Lineage, Drag & drop excel EUCs to SAS 9 & Viya - Data Controller
DevOps and AppDev on SAS 9 / Viya / Base SAS - SASjs
jimbobob
Quartz | Level 8

Hi @AllanBowe ,

 

Trying to use this code as sample, what does this part of the code do:

filename ft15f001 temp lrecl=1000;
parmcards4;

 

AllanBowe
Barite | Level 11

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.

 

/Allan
SAS Challenges - SASensei
MacroCore library for app developers
SAS networking events (BeLux, Germany, UK&I)

Data Workflows, Data Contracts, Data Lineage, Drag & drop excel EUCs to SAS 9 & Viya - Data Controller
DevOps and AppDev on SAS 9 / Viya / Base SAS - SASjs
jimbobob
Quartz | Level 8

Ok very interesting, thanks for update

jimbobob
Quartz | Level 8

@AllanBowe ,

 

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?

AllanBowe
Barite | Level 11
Yes, that's one way of doing it!

We have a bunch of demo SAS web apps you can check out here: https://github.com/search?q=topic%3Asasjs-app+org%3Asasjs+fork%3Atrue&type=repositories

There is also a support group: https://matrix.to/#/#sasjs:4gl.io
/Allan
SAS Challenges - SASensei
MacroCore library for app developers
SAS networking events (BeLux, Germany, UK&I)

Data Workflows, Data Contracts, Data Lineage, Drag & drop excel EUCs to SAS 9 & Viya - Data Controller
DevOps and AppDev on SAS 9 / Viya / Base SAS - SASjs

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 9 replies
  • 2512 views
  • 1 like
  • 3 in conversation