Hi,
We are experiencing issues with establishing a connection between a .NET application and SAS where we want to call SAS Stored Processes using an input data stream in JSON format. We are currently on 9.3 M2 albeit we should be migrating to 9.4 within the next quarter or two.
The issue we are facing is that when we call the stored process from .NET the process seems to hang. We are unsure whether we are not calling the stored process correctly or whether we have not set it up correctly. Any help on how to call SAS Stored processes from .NET is welcome.
Here is what we are doing currently
1. The SAS program. To simplify we are initially just trying to copy the input stream to an output stream. The first step is to use the following SAS program, inspired by the documentation, which works:
filename orig "f:\<path>\orig.txt";
filename copy "f:\<path>\copy.txt";
data _null_;
infile orig ;
file copy;
INPUT ;
put _INFILE_;
run;
2. The stored process: To adapt the SAS program to the stored process I remove the physical file ref ‘orig’ and instead use a fileref instream as follows:
filename copy "f:\AA_SchedOpt\AA_source\macros\copy.txt";
data _null_;
infile instream;
file copy;
INPUT ;
put _INFILE_;
run;
while registering a stored process called ‘instream_TEST’ with the code and a data source named instream as illustrated here
Note that the chosen content type is set to application/x-www-form-urlencoded. I am unsure whether this is correct but relying on documentation here
3.
Here is how we are trying to call the SAS STP from the .NET side
using (var client = new WebClient { UseDefaultCredentials = true })
{
var instream = new WorkOrderModel
{
Description = "Test"
};
client.BaseAddress = _baseUrl;
var subUrl = $"/SASStoredProcess/do?_program=/<server>/STP/instream_TEST&_username={user}&_password={pw}";
return client.UploadString(subUrl, JsonConvert.SerializeObject(instream));
}
Can anybody point to where we should be looking to debug out integration?
regards,
Michael
Hi,
I would recommend that you attach your data payload as a file upload component of a multipart form data POST body, rather than as a named/defined stream. The fileref for your input file will then be assigned dynamically by the STP webapp as documented here. You can then substitute your instream fileref with &_WEBIN_FILEREF, the value of which will typically be that dynamically assigned fileref that looks something like #LN00012, pointing to the temporary uploaded copy of your input file.
Also, consider sending your data to sas as csv over json. It's much faster 🙂
Nik
Hi,
I would recommend that you attach your data payload as a file upload component of a multipart form data POST body, rather than as a named/defined stream. The fileref for your input file will then be assigned dynamically by the STP webapp as documented here. You can then substitute your instream fileref with &_WEBIN_FILEREF, the value of which will typically be that dynamically assigned fileref that looks something like #LN00012, pointing to the temporary uploaded copy of your input file.
Also, consider sending your data to sas as csv over json. It's much faster 🙂
Nik
Hi Nik,
Thanks for your response. It wasn't quite what I had hoped for. However, assuming you were the person behind the h54s adapter your suggestion did weigh in and eventually we have settled for that way of integration. Thanks for the help,
Br, Michael
Cool! FYI in the next couple of weeks we'll be releasing 'v1' of h54s. Very few changes in terms of syntax, but a substantial performance improvement for data payloads bigger than a few KB.
Good luck, feel free to get in touch privately if you hit any snags.
Nik
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!
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.