python executable to run SAS code #389
Replies: 6 comments
-
Hey, no reason other than no one has asked for this. And, sas.submit(open(file).read()) is pretty straight forward. In fact, testing here uses saspy to do testing w/ Viya 4 and they have historically had .sas files they use, so they use open/read to submit them for this case. Of course, they aren't running this from a command line, and routing the outputs to file; there's a different methodology. But, it's just reading .sas files and submitting them. So, having something like this would be useful, though how anyone would want it to behave may vary. I see that this implementation is very close to how a batch submit of a .sas file from the command line with sas itself works. That's certainly a popular use case, so that's cool. saspy supports python batch mode too, so you can write saspy code that is batch submitted via python (like the sas batch submit, but python batch submit). If you'd like to contribute (and perhaps support :) ) a script, like you've shown, to saspy, that would be a nice addition. What you have show is nice and straight forward. I could think of a few tweaks, but it's a nice 'sas batch' style script. Tom |
Beta Was this translation helpful? Give feedback.
-
I would like to contribute and support the script to saspy.
I am open for others to modify it (a few tweaks as you mention) so
that it conforms with saspy coding standards or style.
Please provide me with the instructions for the way forward.
Kind regards
DK
Quoting Tom Weber ***@***.***>:
… Hey, no reason other than no one has asked for this. And,
sas.submit(open(file).read()) is pretty straight forward. In fact,
testing here uses saspy to do testing w/ Viya 4 and they have
historically had .sas files they use, so they use open/read to
submit them for this case. Of course, they aren't running this from
a command line, and routing the outputs to file; there's a different
methodology. But, it's just reading .sas files and submitting them.
So, having something like this would be useful, though how anyone
would want it to behave may vary.
I see that this implementation is very close to how a batch submit
of a .sas file from the command line with sas itself works. That's
certainly a popular use case, so that's cool. saspy supports python
batch mode too, so you can write saspy code that is batch submitted
via python (like the sas batch submit, but python batch submit).
If you'd like to contribute (and perhaps support :) ) a script, like
you've shown, to saspy, that would be a nice addition. What you have
show is nice and straight forward. I could think of a few tweaks,
but it's a nice 'sas batch' style script.
Tom
--
You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub:
#389 (comment)
|
Beta Was this translation helpful? Give feedback.
-
Cool!, Contributing is easy. There's instructions here, https://github.com/sassoftware/saspy/blob/main/ContributorAgreement.txt, for doing it. You just open a PR (Pull Request). See the tab to the left of this one (https://github.com/sassoftware/saspy/pulls). As for the tweaks, I just had 2 thoughts, looking at the code. The first was that you might want to default the filenames for log and lst to be the name of the input file, with .py removed and .log/.lst added. That's the way sas batch submit does it, if you don't override the output file names. Less typing required when submitting the job. Might add a -h for help; print out the help/syntax. The other thing, and I haven't take the time to verify this, but I think it ought to be right. Can you jsut write() the log and lst output to the files directly, as opposed to redirecting stdout and doing a print()? I believe the output has carriage control in it already, such that just writing it directly gets you the same thing in the file. Again, haven't test this out, but I'm expecting to be the case. Either way, whatever works, just thought that's more straight forward. Oh, and one more thing is documentation. Since this isn't a method w/in SASPy, but rather an external script which can be used, I'll have to figure out where it goes, top level directory, or a new 'script' dir? And where to document it. I'll think about that and see what I think is the right way to go. Thanks, |
Beta Was this translation helpful? Give feedback.
-
Hey, I added a 'scripts' directory, since to do a PR, you need to have the code, your script, in the place it would go. So now you can add it in that dir. The doc I'll figure out later, as that doesn't matter for your PR. |
Beta Was this translation helpful? Give feedback.
-
One other thought for this is to add a -r option (results), which defaults to 'text' as you have it. But the other possibility would be html, so that you could run code that produces plots or charts. In this case, if they set -r html, the LST would be written out to .html file instead of .lst (so it would be opened directly as an html file), and the submit would use results='HTML'. Again, writing that out directly would produce a complete html document that could be opened and rendered directly in a browser, or any other UI for opening html documents. |
Beta Was this translation helpful? Give feedback.
-
Here's a quick mock up of where I think documentation would go; in the API section, under a scripts section. This, and the scripts dir, allow for more scrits to be added, if needed, in a general organized way. Obviously once this is finalized, we can add the real doc, but this seems to be the right place. Tom |
Beta Was this translation helpful? Give feedback.
-
Is there any reason why there isn't a python code in saspy package which just executes a .sas file and reports outputs (LOG and LST) to files? Something like this
./run_sas.py -s example_1.sas -l saspy.log -o saspy.lst
I cannot attach my run_sas.py nor example_1.sas, so please find them below.
-- Begin run_sas.py
#!/usr/bin/env python3
import argparse
import saspy
import os.path
import sys
Usage:
./run_sas.py -s example_1.sas -l saspy.log -o saspy.lst
def main():
parser = argparse.ArgumentParser(description="Execute SAS code using saspy.")
parser.add_argument('-s', '--sas_fname',help='name of the SAS file to be executed')
parser.add_argument('-l', '--log_fname', help='name of the output LOG file name')
parser.add_argument('-o', '--lst_fname', help='name of the output LST file')
options = parser.parse_args()
if name == 'main':
main()
-- End run_sas.py
-- Begin example_1.sas
options notes;
data weight_club;
input IdNumber 1-4 Name $ 6-24 Team $ StartWeight EndWeight;
Loss=StartWeight-EndWeight;
datalines;
1023 David Shaw red 189 165
1049 Amelia Serrano yellow 145 124
1219 Alan Nance red 210 192
1246 Ravi Sinha yellow 194 177
1078 Ashley McKnight red 127 118
;
-- End example_1.sas
Beta Was this translation helpful? Give feedback.
All reactions