BookmarkSubscribeRSS Feed
Anna_nag
Obsidian | Level 7

I have installed saspy python package using pip. I am looking for more information on what procedures can saspy run? Is it limited to SAS/STAT and ETS procs or can run any procedures?

 

Thanks for your input in advance.

 

 

4 REPLIES 4
alexal
SAS Employee

@Anna_nag,

 

You should be able to submit SAS code directly from Python session using the submit method:

 

submit(code: str, results: str = '', prompt: dict = []) → dict


This method is used to submit any SAS code. It returns the Log and Listing as a python dictionary.

 

code - the SAS statements you want to execute
results - format of results, HTLML and TEXT is the alternative
prompt - dict of names:flags to prompt for; create macro variables (used in submitted code), then keep or delete


the keys which are the names of the macro variables. The boolean flag is to either hide what you type and delete the macros, or show what you type and keep the macros (they will still be available later).

for example (what you type for pw will not be displayed, user and dsname will):

 

results_dict = sas.submit(
"""
libname tera teradata server=teracop1 user=&user pw=&pw;
proc print data=tera.&dsname (obs=10); run;
""" ,
prompt = {'user': False, 'pw': True, 'dsname': False}
)

For HPA/in-memory procedures, do not forget that the user who started SAS session must have an account that is configured for passwordless SSH (on each machine in the TKGrid cluster).

 

https://sassoftware.github.io/saspy/api.html

Anna_nag
Obsidian | Level 7

Thank you very much for explaining. 

I was wondering why do we need to SUBMIT method if I am able to run simple code like Proc logistics, Proc print etc. using %%SAS magic command?

Are there any specific cases where we need submit method?

Can I still run hp and in-memory procedures simply using proc after %%SAS or does it require any additional license?

 

Appreciate your help.

 

 

alexal
SAS Employee

@Anna_nag,


You can try that. You won't be able to execute HPA procedures without a license for them.

sastpw
SAS Employee

Hey @Anna_nag,

 

As someone mentioned, you need the appropriate SAS license to run whatever SAS code you're trying. saspy is just a client that connects to the SAS system you point it to. That SAS can only do what it's allowed to do. So any code you can run in that SAS install, if you ran it there yourself, will run in that SAS install when you submit it through saspy. saspy has nothing to do with what the SAS session it's connected to can or can't do. Make sense?

 

As for the submit() compared to the magic, the magic is just a jupyter specific 'macro' sort of. All it really does is just take the code you supply and call the submit() method for you. The differences however are that the magic will only display either the output (if there is any) else the log for that code. Calling the submit method yourself returns the output (lst) and log in a dictionary which you can then interact with in the rest of your python code. You can display either or both (lst and log), and you can interact with those via your python code.

 

So, the magic is a shortcut with less functionality than submit itself. Which one you use is just dependent on what functionality you want for the given code you're submitting. Also, there are a number of analytic methods already available in saspy which run various procs. You can run those as methods directly off the specific Analytic Objects (stat, ets, ml, qc ...). However, I don't know if the specific procs you want to run already have methods defined for them in saspy currently or not. You can see what's already in there here:

https://sassoftware.github.io/saspy/api.html#procedure-syntax-statements

 

Hope that helps!

Tom

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

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