Hello firends,
I wrote successfully a stored process that from the lasr table behind the report export a list in a csv file that is written on the server.
Now I want to download this file in a folder on my pc or get the possibility to download it from the browser...
I thougth to create in javascript a link to the path of the csv file, but the _webout process the path in the middle server...
How could I do this?
To get your CSV as a 'file download' (rather than displayed in the browser) you must firstly ensure you don't use the %stpbegin / end macros (as they will play with the output). You must also refrain from sending anything else to the _webout fileref.
You can now set the headers (so the browser knows the data received is a file download) and stream your CSV, as per the below. There is no way to set the save location using SAS, the end user has to do that themselves (eg by changing the default 'downloads' folder or manually choosing via the browser dialog).
data _null_;
rc=stpsrv_header('Content-type','text/plain');
rc=stpsrv_header('Content-disposition',"attachment; filename=YOURCSVNAME.csv");
run;
data _null_;
file _webout;
infile "/yourcsvlocation/your.csv";
input;
put _infile_;
run;
To get your CSV as a 'file download' (rather than displayed in the browser) you must firstly ensure you don't use the %stpbegin / end macros (as they will play with the output). You must also refrain from sending anything else to the _webout fileref.
You can now set the headers (so the browser knows the data received is a file download) and stream your CSV, as per the below. There is no way to set the save location using SAS, the end user has to do that themselves (eg by changing the default 'downloads' folder or manually choosing via the browser dialog).
data _null_;
rc=stpsrv_header('Content-type','text/plain');
rc=stpsrv_header('Content-disposition',"attachment; filename=YOURCSVNAME.csv");
run;
data _null_;
file _webout;
infile "/yourcsvlocation/your.csv";
input;
put _infile_;
run;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.