Hello Team ,
I am trying to create a CSV file by calling server side Storeprocedure
Server side STP :
%global param1 ;
%global status output_1 ;
options minoperator mindelimiter=' ';
%let datestamp=%sysfunc(translate(%sysfunc(today(),yymmdd10.),_,-));
%let Tgt_File=/home/ user/log_&datestamp..csv ;
data STATUS_file;
format status $5.;
format status_Message $200.;
%if (%quote(¶m1.) in A B C D) %then %do;
%let status=OK;
%let output_1 =%quote(Testavailable;¶m1.);
data File_out;
log_1="&output_1.";
run;
data _null_;
set File_out;
file "&Tgt_File" dsd MOD ;
put (_all_) (+0) ;
run;
%end;
%else %do;
%let status=Error;
%let status_Message=%quote(Invalid input parameters "¶m1.");
%end;
run;
%put &=status &=output_1;
Client side Program : when we are trying to call the store procedure
filename inputf temp;
filename outputf temp;
%let input_file = %sysfunc(pathname(inputf));
%let output_file = %sysfunc(pathname(outputf));
data _null_;
file "&input_file.";
put '<Test_file_STP>';
put '<parameters>';
put '<param1>A</param1>';
put '</parameters>';
put '</Test_file_STP>';
run;
/* Disable certificate use */
options set = SSLREQCERT "NEVER";
proc http
method="POST"
url="https://exampleurl.net:0000/SASBIWS/rest/storedProcesses/Test_file_STP"
in=inputf
out=outputf
WEBUSERNAME="C_Username"
WEBPASSWORD="C_password"
AUTH_BASIC;
DEBUG level=3; /* Add debugging information to log */
headers "Content-Type"="application/xml";
run;
expected result :
it should create a file in desired location
and send response as below
<test_file_STPResponse>
<test_file_STPResult>
<Parameters>
<status>OK</status>
<output_1>Testavailable;A</output_1>
</Parameters>
</test_file_STPResult>
</test_file_STPResponse>
when we run the client program doesn't returns expected result , it throws
HTTP Status 500 – Internal Server Error , instead of expected result
Is there a reason you are using BIWS? As you can see, it involves some security issues, such as embedded passwords and disabled certificates in your case.
Just create a regular STP and call it using PROC STP - here's an example:
%let appLoc=/Public/app; /* Metadata or Viya Folder per SASjs config */
/* compile macros (can also be downloaded & compiled seperately) */
filename mc url "https://raw.githubusercontent.com/sasjs/core/main/all.sas";
%inc mc;
/* create an STP */
filename ft15f001 temp;
parmcards4;
/* write a file to the file system */
data _null_;
file "/tmp/dc/example.txt";
/* write a parameter sent from the client */
put "&myparam";
run;
;;;;
%mp_createwebservice(path=&appLoc/example,name=makefile)
/* now call the STP with a param */
proc stp program="&apploc/example/makefile";
inputparam myparam="Hello, file!";
run;
/* check the file was created */
data _null_;
infile "/tmp/dc/example.txt";
input;
list;
run;
Result:
The following macro is also helpful for testing SAS web services (on both SAS 9 and Viya): https://core.sasjs.io/mp__testservice_8sas_source.html
In any case, I would recommend examining the web server logs to further understand the cause of your internal server error. If you are looking to compile and deploy Stored Processes as web services, you could also look at https://cli.sasjs.io -> it provides DevOps for SAS Apps as well as a mechanism for documenting and testing your services, jobs & macros. More info here: https://sasjs.io/resources/
Just to throw another option into the mix - we recently open sourced our (Analytium) sas9 REST API - it's available here on github: https://github.com/analytium/sas9api
It provides REST endpoints for all manner of SAS functions such as listing libraries, fetching datasets, listing users & groups etc.
Hello @learn_SAS_23
As I understand it, a file will be server to the server and this files has to be saved as a csv file at the desired location.. This has to be performed using webservice and stored procedure.
Please have a look at the following.
1. https://communities.sas.com/t5/SAS-Stored-Processes/Uploading-a-file-through-an-html-form/td-p/20312...
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.