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

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;

 

1 ACCEPTED SOLUTION

Accepted Solutions
Quentin
Super User

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.

BASUG is hosting free webinars ! Check out recordings of our past webinars: https://www.basug.org/videos. Save the date for our in person SAS Blowout on Oct 18 in Cambridge, MA. Registration opens in September.

View solution in original post

2 REPLIES 2
Quentin
Super User

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.

BASUG is hosting free webinars ! Check out recordings of our past webinars: https://www.basug.org/videos. Save the date for our in person SAS Blowout on Oct 18 in Cambridge, MA. Registration opens in September.
rakeon3
Fluorite | Level 6
Hi, I have resolved by removing %stpbegin and %stpend and the options / nokeys nosastags,

Thanks

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 291 views
  • 1 like
  • 2 in conversation