BookmarkSubscribeRSS Feed
learn_SAS_23
Quartz | Level 8

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(&param1.) in A B C D) %then %do;
%let status=OK;
%let output_1 =%quote(Testavailable;&param1.);
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 "&param1.");
%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 

 

4 REPLIES 4
AllanBowe
Barite | Level 11

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:

AllanBowe_0-1631182549144.png

 

 

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/

/Allan
SAS Challenges - SASensei
MacroCore library for app developers
SAS networking events (BeLux, Germany, UK&I)

Data Workflows, Data Contracts, Data Lineage, Drag & drop excel EUCs to SAS 9 & Viya - Data Controller
DevOps and AppDev on SAS 9 / Viya / Base SAS - SASjs
learn_SAS_23
Quartz | Level 8
Yes, we are supposed to use SAS BIWS , The requirement is to use to store procedure to create the CSV file from input data received from the client (such as Curl,soap API , or even sas from above client example)

-> can you guide me how to check the webserver logs to analyse internal server error (Http:500) , i couldn't see much details about the error when executing the client program)
AllanBowe
Barite | Level 11

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.

/Allan
SAS Challenges - SASensei
MacroCore library for app developers
SAS networking events (BeLux, Germany, UK&I)

Data Workflows, Data Contracts, Data Lineage, Drag & drop excel EUCs to SAS 9 & Viya - Data Controller
DevOps and AppDev on SAS 9 / Viya / Base SAS - SASjs
Sajid01
Meteorite | Level 14

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... 

2.https://documentation.sas.com/doc/en/itechcdc/9.4/stpug/p0jqbnv7miosidn1xw3tqe3f0hv0.htm#n0dye76j76r... 

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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
  • 4 replies
  • 807 views
  • 3 likes
  • 3 in conversation