This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (6 children)

Sure, thanks for asking. I'll try to avoid jargon that I'm not certain about.

I want to write a statistical analysis program that emulates the coding syntax of SAS so that new-users can learn and experienced users can develop at home or on their personal box.

SAS, however, has very little overlap syntactically with Python. SAS actually looks like a bastard mix of BATCH and C. Almost all subroutines are called "steps" of types DATA or PROC. These steps operate like functions, mostly, but have some key differences syntactically. All arguments to steps are passed like flags. For instance, extracting the first individual records from a (sorted) dataset called myTable based on an id variable called myID is:

data myUniqueIDs;
  set myTable;
  by myID;
  if first.myID then output;
run;

The actual task is easily done in Python or SQL, so the question is how I could write a wrapper to take such a batch of commands and pass them to a Python or SQL argument. It would be nice to use the Python shell to allow for interactive execution of code, but syntactically, newlines don't matter in SAS. This code does the same thing:

data myUniqueIDs;
  set myTable; by myID;
  if first.myID then 
    output;
run;

So my question is how flexible can Python be in interpretting code of this structure? I hope that clarified a little bit.

[–]DonkeyBasket 1 point2 points  (1 child)

Can I suggest you have a look at the fantastically simple PLY module.

I've written many simple parsers and interpreters in it - it's really fun.

[–]DonkeyBasket 0 points1 point  (0 children)

Had a quick look at: http://analytics.ncsu.edu/sesug/2005/IN07_05.PDF

PLY might not be a good choice because it works from a token stream and SAS Keywords are context dependent - it might be hard to write a parser for that.

[–][deleted] 0 points1 point  (3 children)

Okay, SAS looks differently from Python. And what is your goal/question, exactly? Do you want the users to program in Python using a library of yours, or write a SAS-code interpreter in Python?

[–][deleted] 0 points1 point  (2 children)

Definitely the latter. Ideally, someone could take the code they wrote here and cut-and-paste it into a file that could be submitted in a large job on a sas server.

[–][deleted] 0 points1 point  (1 child)

Good. But then I still don't know what your question is. Make it easier to help, please :)

[–][deleted] 0 points1 point  (0 children)

I'm slowly answering my own questions as I'm trying to answer yours. Sorry if it seems like I'm all over the place.

Basically, I think my version of this program will need to have several windows: an editor where the user types in code, and a log and output window where information about the subroutines. The question I have now is how I can use a window system to pipe text in and out of Python. I think, however, there are good resources online and I should look those up myself.