Hey Everyone,
I'm having trouble displaying only specific graphs when a back-end SAS program is ran using SASPy. For the sake of simplicity, I have the following code:
import saspy import os from IPython.display import HTML ### os.environ["PATH"] += INSERT PATH NAME IF NEEDED ### sas = saspy.SASsession(cfgname="winlocal") sas.symput("SASPGRM", "[INSERT PATH NAME OF SAS FILE]", quoting=None) sas_submit_return_value = sas.submit( """ %INCLUDE "&SASPGRM"; """) ### Sucessful when using Jupyter Notebook ### HTML(sas_submit_return_value['LST'])
where code for the SASPRM is:
TITLE "PLOT 1";
PROC SHEWHART DATA=SASHELP.CARS;
SYMBOL V=DOT;
IRCHART ENGINESIZE*MAKE / OUTTABLE=CHRTVIOL1(WHERE=(_TESTS_ NE ''));
RUN;
QUIT;
TITLE "PLOT 2";
PROC SHEWHART DATA=SASHELP.CARS;
SYMBOL V=DOT;
IRCHART ENGINESIZE*MAKE / OUTTABLE=CHRTVIOL2(WHERE=(_TESTS_ NE ''));
RUN;
QUIT;
TITLE"PLOT 3";
PROC SHEWHART DATA=SASHELP.CARS;
SYMBOL V=DOT;
IRCHART ENGINESIZE*MAKE / OUTTABLE=CHRTVIOL3(WHERE=(_TESTS_ NE ''));RUN;
QUIT;
Typically, when I want to only display specific graphs, I can use PROC GREPLAY and specify the graphs that are saved in a temp catalog in WORK.GSEG or really any permanent catalog defined in a GOUT statement. I've noticed that when running these procedures in my SAS Environment, the GSEG catalog is created in the same location as my WORK directory. However, when running the code in the submit block using SASPy, the catalog doesn't appear but the SAS datasets do appear. Note: The log states that the "Body file: _TOMODS1" was created in the work directory location. Even though this file is created, it is either deleted or invisible in the windows file explorer.
The question is, are there similar functions like GREPLAY in SASPy? I've tried using the GOUT option but the defined catalog isn't created like it does in my SAS Environment. I only want to create pdf files if the user wants them by selecting a custom button in my Python application.
Do any of you have any insights or comments? Note: We're restricted from changing any back-end SAS programs so any solutions that requires changing the SAS Program itself would probably be a non-starter within my organization.
Thanks!
If you add "ods graphics on;" to your program, will you get the outputs you want? That should trigger ODS graphics instead of traditional GRSEG output. I don't know if the graphics produced will have parity/appearance that you want.
For my use case, I would imagine having ODS turned on would trigger output for everything in the %INCLUDE statement. I was wondering if I could be more selective if the user only wants to see a graph. For example, if I had both PROC UNIVARIATE with the default output and a histogram and PROC SHEWHART with an I&MR chart in my back-end SAS program and I wanted to only show the histogram (not the output or the PROC SHEWHART chart) to the user as a pdf. The user would select the "HISTOGRAM" button and a SUBMIT CONTINUE clause with PROC GREPLAY would run in the original SAS/AF application. The SAS/AF application pulls the graph objects (or files, I don't know) in the WORK.GSEG catalog enabling this feature in our application to run seamlessly.
The approach to adopt a similar goal using ODS graphics: you would use ODS SELECT to tell SAS which pieces of output you want to keep. Use ODS TRACE to see the SAS-names for each of the outputs generated, then use ODS SELECT to say which you would like and then rerun. Or you can also use PROC DOCUMENT to "replay" just the parts you want from an already generated set of work.
Several blog posts here to help you get started. This community post also shows an example.
Chris,
Sorry, it's been a few weeks. I've been studying more up on PROC DOCUMENT and see how powerful this procedure really is.
I tried using PROC DOCUMENT to save a catalog of the items that were already generated. However, I'm getting output that's close but not exact. For example, the SYMBOL V=DOT option in PROC SHEWHART from the code above doesn't seem to work the same way it does in the SAS environment. I'm able to get the basic components of the graph but not this additional option. Similarly, the defaults seem to display the subgroup indices (x-axis) vertically while the PROC DOCUMENT REPLAY displays the indices (x-axis) horizontally.
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.