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.

The Boston Area SAS Users Group is hosting free webinars!
Next up: Troy Martin Hughes presents Calling Open-Source Python Functions within SAS PROC FCMP: A Google Maps API Geocoding Adventure on Wednesday April 23.
Register now at https://www.basug.org/events.

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.

The Boston Area SAS Users Group is hosting free webinars!
Next up: Troy Martin Hughes presents Calling Open-Source Python Functions within SAS PROC FCMP: A Google Maps API Geocoding Adventure on Wednesday April 23.
Register now at https://www.basug.org/events.
rakeon3
Fluorite | Level 6
Hi, I have resolved by removing %stpbegin and %stpend and the options / nokeys nosastags,

Thanks

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

Register now!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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