2

I tried with SASpy but it's not working. I am able to open the SAS .egp file but not able to run the multiple scripts within in sequence.

import os, sys, subprocess
def OpenProject(sas_exe, egp_path):
    sasExe = sas_exe
    sasEGpath = egp_path
    subprocess.call([sasExe, sasEGpath])

sas_exe = path\path\
egp_path = path\path\path\

OpenProject(sas_exe, egp_path)
Abhi
  • 21
  • 3
  • 1
    Please share some code so we can have the context of your problem. – Vukašin Manojlović Dec 12 '20 at 14:10
  • Welcome to Stack Overflow! You are more likely to get an answer if you describe the steps you have taken to try to solve the problem including the research you've done. See how to ask a good question on SO here: https://stackoverflow.com/help/how-to-ask – jeffhale Dec 12 '20 at 14:39
  • Is the project entirely embedded within EG? You can call EG to run a specific project. Within EG, click "schedule" and it will generate some VB code you can call to execute it with other software. If everything in EG is saved as external SAS program files, you can simply call a single .sas file in SAS batch that runs each program you need in the right sequence. Generally I'll have a single .sas master file with %includes to all my code and run this one file in SAS batch mode. I'm not a huge fan of embedding SAS code into EG project files. – Stu Sztukowski Dec 13 '20 at 17:06
  • @VukašinManojlović I have shared the code above. Please see. – Abhi Dec 14 '20 at 19:41
  • @StuSztukowski Everything in the SAS Enterprise Guide is saved as ".egp" project is saved in the form of multiple steps. Like "SampleProject.egp" has Step1, Step2, Step3 etc as codes. I clicked on schedule but how can saved the VBS script. – Abhi Dec 14 '20 at 19:55

1 Answers1

1

This depends a bit on exactly what the workflow is. A few side notes, then the full solution.


First: EGP is not really intended to store production processes, in my opinion. EGP should really be used for development, then production is done with .sas (text) files. EGP can directly store the nodes as .sas files; ask a new question about that if you want to know more, but it's pretty easy to figure out. Best practice is to have EGP save the code modules as .sas files, then run those - SASPy will easily do that for you.

Second: If you use SAS's built-in Git connectivity, then you can do this a bit more easily I suspect. Consider doing that if you already use Git for your other processes. Again, then you end up with a .sas file, and can directly run that via SASPy.


So: how can you do this in Python, with the assumption you do have to use the .egp itself, without too many different moving parts? The key here is the .egp format. EGP is a container file, which is actually a .zip format container that has in it, among other things, all of the SAS code you want to run, as text. Text in xml format, but still, text.

You can write a python program that opens the .egp as a .zip file, using the zipfile library, and then use xml.etree.ElementTree to parse the project.xml file inside that project. Exactly what you do from there depends on your particular details, and is well out of scope for a Stack Overflow answer, but if you do better visually you can simply rename the .egp to .zip and then open in unzip program of your choice, then browse project.xml in your text editor, and find the nodes and code related to those nodes.

You can then extract the .sas code as text, and submit it directly via SASPy, or extract it to a .sas file and then submit that however you prefer (SASPy or something else).

I do something similar to this for a project - I don't actually run code from it, I'm just parsing it to verify that the correct programs were synced from the EGP to production - but it would be trivial to actually submit the code from what I've written, which is about 50 lines of code total. I may write a SGF paper this year or next year on this topic, in which case I'll try and remember to submit it here - or you can head over to my github page and see if it's there (in the future!).

Joe
  • 62,789
  • 6
  • 49
  • 67
  • Joe, I can open the egp file, my issue is how can I run the code that are as a node within that egp file. Can you help me understand that? – Abhi Dec 15 '20 at 16:01
  • @Abhi Well, once you parse the `project.xml` inside the egp and find the code node you want to run, you can submit that code with SASPy using `sas.submit` and the text. – Joe Dec 15 '20 at 16:06
  • Or if you mean you can open it manually, then you should be able to save the code inside those nodes in .sas files separately, if you're going that route. – Joe Dec 15 '20 at 16:13