Hi, I’m creating a web page via a stored process. This web page calls another stored process which should return the JSON of a SAS table via the proc json out=_webout
. When I make the request, I get this error:
ERROR: File is in use, _WEBOUT.
ERROR: Due to the previous error, the JSON output file is incomplete and invalid, or in some cases, unable to be created. If created, the JSON output file is retained so that you can review it to help determine the cause of the error.
I’m using SAS 9.4
What can I do to resolve this problem?
this is code sas:
%put &=data_format; filename filecsv "ttt_&data_format..csv"; %stpbegin; %macro check_file_exists; %if %sysfunc(fexist(filecsv)) %then %do; %put 'The file filecsv exist'; data ttt; infile filecsv truncover firstobs=2; input a b $26. c $ d $ e $ f $60. ; run; proc json out=_webout pretty; write open object; write values "data"; write open array; export ttt / nokeys nosastags; write close; write close; write close; run; %end; %else %do; %put 'The file filecsv does not exist'; %end; %mend check_file_exists; %check_file_exists; %stpend;
My guess when you call %sptbegin, it is generating an ODS statement that directs output to _webout. So you could try removing %stpbegin and %stpend, and see if that works.
I think you might also need to set content type headers to tell the browser the content is a json file. See this related post: https://communities.sas.com/t5/SAS-Programming/JSON-based-stored-process-works-fine-in-SAS-stpweb-ap... . I like Bruno's suggestion to write the json to a file, so you can see the file, then you can stream the file to _webout. I think you could do it something like (untested):
data _null_;
file _webout recfm=s;
infile "&myinfile" recfm=n;
if _n_ = 1 then do;
rc = stpsrv_header('Content-type','application/json');
rc = stpsrv_header('Content-disposition',"attachment; filename=MyJson");
end;
input c $char1.;
put c $char1. @@;
run;
That's code to do a binary copy of a file from an old post I can't find now https://support.sas.com/kb/6/588.html , but there are better ways.
My guess when you call %sptbegin, it is generating an ODS statement that directs output to _webout. So you could try removing %stpbegin and %stpend, and see if that works.
I think you might also need to set content type headers to tell the browser the content is a json file. See this related post: https://communities.sas.com/t5/SAS-Programming/JSON-based-stored-process-works-fine-in-SAS-stpweb-ap... . I like Bruno's suggestion to write the json to a file, so you can see the file, then you can stream the file to _webout. I think you could do it something like (untested):
data _null_;
file _webout recfm=s;
infile "&myinfile" recfm=n;
if _n_ = 1 then do;
rc = stpsrv_header('Content-type','application/json');
rc = stpsrv_header('Content-disposition',"attachment; filename=MyJson");
end;
input c $char1.;
put c $char1. @@;
run;
That's code to do a binary copy of a file from an old post I can't find now https://support.sas.com/kb/6/588.html , but there are better ways.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.