BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Berliner_Ørsted
Fluorite | Level 6

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

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. 

  1. The .NET side

 

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

1 ACCEPTED SOLUTION

Accepted Solutions
boemskats
Lapis Lazuli | Level 10

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

View solution in original post

3 REPLIES 3
boemskats
Lapis Lazuli | Level 10

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

Berliner_Ørsted
Fluorite | Level 6

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

boemskats
Lapis Lazuli | Level 10

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

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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
  • 3 replies
  • 1765 views
  • 1 like
  • 2 in conversation