BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
AsSASsin
Quartz | Level 8

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?

1 ACCEPTED SOLUTION

Accepted Solutions
AllanBowe
Barite | Level 11

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;

 

/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

1 REPLY 1
AllanBowe
Barite | Level 11

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;

 

/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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

Tips for filtering data sources in SAS Visual Analytics

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.

Discussion stats
  • 1 reply
  • 1201 views
  • 0 likes
  • 2 in conversation