BookmarkSubscribeRSS Feed
PrinceAde
Obsidian | Level 7

Hi everyone, Please I need help to address integrating SAS into PHP.

 

I'm trying to integrate SAS code into PHP that can deal with data manipulation using data step, proc sql, it will also use macro, etc. We have the code completed in SAS already, the code also make a macro call to another macro, it calculates Overall Concordance Correlation coeficient based on Barnhart equation, using %include. How can I integrate this existing programs into PHP(We are building an application using PHP).

Thank You. 

12 REPLIES 12
ChrisNZ
Tourmaline | Level 20

Can you call external programs using PHP?

PHP is generally running on web servers. Is SAS installed there too?

If not, you'll need to use a remote shell to connect to the SAS server and run a command there. And then recover the result.

 

Alternatively, you could put the SAS code in a SAS Stored Process and call that. See different discussions about what can be done

https://stackoverflow.com/questions/51885979/how-can-i-call-a-sas-stored-process-from-curl-within-ph...

https://stackoverflow.com/questions/39641819/run-long-sas-stored-proc-from-php-without-hanging-brows...

https://stackoverflow.com/questions/43254184/sas-connection-with-php

Or even this one where a stored process page is called using Python (but it could be called using any other language)

https://stackoverflow.com/questions/35567259/sas-stored-process-to-a-web-service-link

 

 

 

Ksharp
Super User
You can use PHP to run a BAT file to run a SAS Programm.
E.X.
1)Create a BAT file c:\temp\have.bat in which there is a command to run a sas programm "c:\temp\temp.sas" . Like:
"D:\SASHome\SASFoundation\9.4\sas.exe" -nosplash -sysin "c:\temp\temp.sas" -log "c:\temp\temp#Y#m#d-#H-#M-#s.log" -logparm "rollover=auto"

2)Under command line,you can execute this BAT file by PHP.
c:\temp\have.bat
JuanS_OCS
Amethyst | Level 16
Thank you for posting this question!
As former web developer my initial answer is very much in the direction of your first reply, leveraging any web based protocol. For this, the SAS Stored Processes (who can also be defined as web services), used to be my go to solution for J2EE and PHP.

Nowadays perhaps I would evolve my reply in the following way, in addition to above, trying to leverage the function of SASPy:

Direct integration of SASPy as a PHP module is not practical because of the language and runtime differences. However, you can still leverage SASPy in a PHP environment through these techniques:

1. Direct execution of Python scripts from PHP, preparing your SASPy module in your exec function.
2. Web service approach using Flask or another framework.
3. Messaging queues like RabbitMQ for more complex and asynchronous tasks.

Each method has its pros and cons, depending on your performance, scalability, and architectural requirements.

SASPy has some requirements on version of Python, and it could potentially affect performance too, depending on its usage (Python code). The best would be to make IOM or SSH calls from SASPy, and not running a lot of additional code in Python, to keep it as lightweight as possible.
PrinceAde
Obsidian | Level 7

@JuanS_OCS  Thank you very much. These are interesting options.

I'm interested in these options, especially in relation to cost. Are they cost effective?

JuanS_OCS
Amethyst | Level 16
SASPy has no additional costs, therefore none of these 3 options should cost, except for a bit of effort to test and implement it. Performance testing would have same costs as any other tool or application, of course.

Same goes for the SAS Stored Processes option: for as long as you have SAS with middle tier, no added cost and the calls would be similar as to any web API call.
jlibster
Calcite | Level 5

I'm new to SAS  but as a software developer whose done a number of mixed stacks with PHP including Java/PHP I would strongly advise not to mix them directly. Tends to get convoluted and the work required in my experience had poor ROI. The hacks to get Java working in PHP reliably or even calling Java binaries isn't ideal. Calling Python binaries/scripts generally I've found less problematic but still not ideal.  Would be better to have the data/tasks distributed through some JSON friendly service (a Rest API basically) or queue service. Probably easiest to do in Python if there is a learning curve involved. Once done it easy to call that service via the web server/PHP.

ChrisNZ
Tourmaline | Level 20
Dumping trigger files in a folder monitored by SAS is certainly a reliable way to execute SAS jobs. The downside is the loss of perfect synchronicity.
AlanC
Barite | Level 11

I have used SAS in ASP.NET and Blazor apps. Same concept should apply for PHP. IMO, you don't need to do bat or any command shell code. They do not scale and are really not integrated into the system. I have had SAS running in hundreds of instances doing web requests.

 

Ok, how? Using SAS Integration Technologies which should be installed at your site. Here is C# code (full listing here: https://github.com/savian-net/SasDotNetTipsTricks😞

 

ws = new SAS.Workspace();
var lang = ws.LanguageService;
lang.Submit(code);

 

Chris Hemendinger has written extensively on using IntTech with various technologies. He may have something on PHP. Basically, use the SAS mechanisms to submit code vs using a shell. A shell should work but a better means is the SAS tech you already have. You can use other SAS means such as Stored Process/Procedure? but IntTech is how it works and also how EG works. Skip the middlemen.

 

Watch for SAS license constraints for your shop: this is a technical answer only.

  

https://github.com/savian-net
JuanS_OCS
Amethyst | Level 16
I agree on skipping middle software/calls as much as possible.

The Integration Technologies client from SAS has a few challenges though, which would need to checked with SAS support or your SAS account manager:
1. Costs: it has a license impact
2. Availability: not sure if SAS is selling this license individually anymore. Last time I tried there was some push back. It might depend on region or particular situation though.
3. Feasibility: the theory looks like excellent, but unless there is a library implementation, it’s a no-go.

As of today and as far as my knowledge goes, the “implementation” goes through PHP-Python-SASPy-SAS. But, indeed, perhaps someone like Chris or Joe Furbee has this insight!
AlanC
Barite | Level 11

Not sure on license impact. Most clients who use SAS already have IntTech licensed due to EG.

 

I am unsure what you mean about library implementation. What are you referring to? You add the dll, call it, and you are done. The dll is simply the IntTech COM dlls. I do this at every SAS client, pretty much, and have been for decades. Works like a champ.

 

3 considerations:

  1. License
  2. Security and making sure you can access it
  3. Speed of SAS startup. i start it up and leave it in memory to reduce initialization time 
https://github.com/savian-net
JuanS_OCS
Amethyst | Level 16
Mhm. Security and licensing are certainly important considerations, for anyone working with COM or FFI.
Leaving license aside, if anyone goes for this option you indicate, I’d strongly suggest to wrap it in a custom PHP extension and add security measures. Wondering how you tackle security concerns towards Penetration Tests and Audits? Feeling curious, Alan 🙂

AlanC
Barite | Level 11

There is nothing unusual about this. This is how SAS works in their own products (ex. EG). IntTech has been around, in some form, for decades and it is used to do this integration (code, logs, metadata, etc.). There are plenty of papers on it ranging from VBScript, VBA, C#, etc.

 

If the concern is that someone will submit malicious code, what I did was just stored the codes files and passed parms in via Swagger or some similar means.  

https://github.com/savian-net

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
  • 12 replies
  • 1548 views
  • 4 likes
  • 6 in conversation