BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.

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 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 1342 views
  • 1 like
  • 2 in conversation