Exploring, predicting and reporting with SAS Visual Analytics and SAS Visual Statistics

Stored Process to export a CSV in SAS VA 7.3: how to export to local host?

Accepted Solution Solved
Reply
Contributor
Posts: 40
Accepted Solution

Stored Process to export a CSV in SAS VA 7.3: how to export to local host?

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?


Accepted Solutions
Solution
‎11-30-2017 01:05 AM
Contributor
Posts: 58

Re: Stored Process to export a CSV in SAS VA 7.3: how to export to local host?

[ Edited ]

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
Think you know SAS? Take the sasensei challenge..

View solution in original post


All Replies
Solution
‎11-30-2017 01:05 AM
Contributor
Posts: 58

Re: Stored Process to export a CSV in SAS VA 7.3: how to export to local host?

[ Edited ]

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
Think you know SAS? Take the sasensei challenge..
☑ This topic is solved.

Need further help from the community? Please ask a new question.

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