Sunday, October 14, 2012

New Sublime Text package available for SAS Programming


Please use my SAS Package for Sublime Text

I started writing a crazy long treatise on why I like text editors, but really the information I want to put out is this: I've been working on a package for SAS programming with the Sublime Text 3 editor, which I believe is really functional & I would love to get feedback on how to make it better.

I'm using this as my main editor now--have not opened up UltraEdit in literally weeks and could not be happier.

Installation

You will find the package in this github repository.  Installing it amounts to causing the files in that repo to be copied to a new subdirectory under the location where Sublime Text is putting your packages (which you can find out by choosing the 'Browse Packages...' item off the 'Preferences' menu).  There are 2 good ways to do this:

If you've got git


Open a command prompt, cd over to the location where your Sublime packages are stored, and type:
git clone git@github.com:rpardee/sas.tmbundle.git SAS
The nice thing about doing it that way is that you can update the repo anytime thereafter with a simple
git pull
In the package subdirectory.

If you don't have git

The easiest thing would be to download this zip file and extract it to a new SAS subdirectory that you create in your Packages directory.

What do I get?  What's working?

The package includes:
  1. A mostly written-from-scratch SAS program syntax definition file, so syntax highlighting works (including SAS' wonky comment style) and the symbol list gets populated w/dataset & macro names.
  2. Likewise, a SAS log syntax definition file, which highlights NOTEs, INFO messages and of course ERRORs.
  3. A build system (windows-only at the moment) which:
    1. Batch-submits the currently-showing file,
    2. Waits for the program to finish,
    3. Scans the resulting .log file for errors/warnings w/a fairly sophisticated regex (which e.g., ignores license expiration WARNINGs), popping a dialog indicating whether the log is clean), and then
    4. Opens the log file for viewing.
  4. A command to skim through log files, jumping right to ERRORs and WARNINGs, by default bound to ctrl-e.  So just skip from trouble spot to trouble spot by hitting ctrl-e!
  5. A bunch of very useful snippets.

What's not working yet or is still to be done?

My to-do is:
  1. Rewrite the build script (currently a windows script file) as a python command to make it portable across platforms. SORT OF DONE
  2. Incorporate this package into Package Control , to make installation & updating that much easier.
  3. Move the Roy- and Group Health-specific snippets out of the package & into my User package.
  4. Moar snippetts!

Credits

Many many thanks to Jiangtang Hu, whose fork of Jakob Stoeck's SAS bundle was the beginning of my hope that I could profitably use Sublime Text for SAS programming!

Edit!

Looks like there have been late comments to this post, with error reports.  Terribly sorry not to reply--I did not get notification about the comments.

Would anyone who's having trouble please log an issue at the github repository please?

Also--please note that I am no longer supporting sublime text 2 (even though it's nominally the current version).  ST3 has been out for more than a year (?) now, is very stable, and that's all I have installed anywhere, so I'm not in a good position to support ST2.  Sorry!

Thank you!

36 comments:

  1. Good job Roy! Thank you for put all together.

    ReplyDelete
  2. Thank you -- I just installed it and my first impression is that this is a godsend!

    ReplyDelete
  3. Thank you Roy, it's a very useful tool. Keep up the good work! Congratulation!

    ReplyDelete
  4. Thank you ! 'Build work as expected : )

    ReplyDelete
  5. I think I've got the indent rules working (crude ones at least).

    ReplyDelete
  6. thanks a lot for the work. I am trying to use this package under the sublime beta 3 and was getting the error of 'invalid registry key'

    ReplyDelete
    Replies
    1. Hey Rong,

      Terribly sorry for the trouble--you're not the only one to run into this.

      The short of it is--update the package and the problem should go away.

      I'll put some more detail up on this issue here:

      https://github.com/rpardee/sas.tmbundle/issues/6

      Cheers,

      -Roy

      Delete
  7. Thanks for this.

    What would be the easiest way to get the build system working with a remote workspace server?

    ReplyDelete
    Replies
    1. Ach--I'm afraid I've never worked with that product & so don't know. For whatever it's worth, my standard header snippet %include's a file that starts up a sas/connect session on a remote server. So all of my work takes place remotely. No idea if that could work for remote workspace server.

      If you play with that & find something that works, do please let me know. Maybe it could be incorporated?

      Delete
  8. Many thanks Roy! This is wonderful!! I can build on both Windows and Linux by only adjusting the path of SAS.

    ReplyDelete
  9. Minkai -- where did you adjust the path? I've tried and failed in run_sas_program.py. I still get an error telling me to adjust the path in a file that doesn't exist (sas.sublime-settings).

    Roy, could suggest where to edit the package to get the build function working on linux?

    Syntax highlighting works great! Thanks!

    ReplyDelete
    Replies
    1. Sorry to take so long to respond. The sas.sublime-settings file should be created in the same location where user settings are. So if you select 'Settings - User' off the Preferences menu, a file named Preferences.sublime-settings should come up--sas.sublime-settings should appear in that same location (so you could e.g., right-click in the file & select 'Open containing folder...' while looking at Preferences.sublime-settings to get a new explorer window in that same folder.)

      Delete
  10. Awesome!!
    I can finally let go of SAS EG

    Thank you very much

    P.S.
    the "git" command did not work for me, I get a "permission denied (publickey)" so I downloaded the zip file.

    ReplyDelete
  11. Bookman - I am having the same issue.

    The problem,I think, is line 91 of "run_sas_program.py" which reads
    "sas_path = s.get('sas-path', "C:\\ProgramFiles\\SAS\\SASFoundation\\9.2\\sas.exe")".


    I try to create the file sas.sublime-settings with my setting as "sas_path=C:\\ProgramFiles\\SASHome\\SASFoundation\\9.3\\sas.exe"
    but it did not work

    ReplyDelete
    Replies
    1. yes, I have the same issue. I guess have to recompile the py file?

      Delete
    2. I found a work-around for this problem. See below.

      Delete
  12. This is brilliant. Best colouring for SAS imho. Only close is ESS and SlickEdit and that does not get x= y*z ; correct :-)

    ReplyDelete
  13. I found a nice workaround --at least on Windows 7 -- for the problems Bookman has reported and I had too. If you have admin rights I created a virtual folder for C:\\ProgramFiles\\SAS\\SASFoundation\\9.2\\sas.exe where this program looks. Do do this, following these instructions:

    1. Create the following folder on your system if it does not already exit: C:\Program Files\SAS\SASFoundation

    2. Locate the directory where your current version of SAS is installed. For me it was "D:\Program Files\SASHome\SASFoundation\9.4\." Make note of this location as it will be used in the next step.

    3. Create a virtual folder by issuing the following system commands in a windows command prompt:

    mklink /D "C:\Program Files\SAS\SASFoundation\9.2" "D:\Program Files\SASHome\SASFoundation\9.4\"

    Of course, you will replace the second entry "D:\. . . " with the location of our sas.exe file.

    That should do it.

    ReplyDelete
  14. Does anyone know if it's possible to get the log to display in a separate detached window? It seems the log always comes up in a tab in the same window?

    ReplyDelete
    Replies
    1. I don't know how to do that w/the python build (main branch of repo). That's almost certainly my ignorance of python & the sublime libs--sorry about that. I'd be happy to take a pull request if anybody wants to create one that elaborates the build system to allow this as an option.

      If you are on windows you can try the wsf_build branch, which will just open the .log file up in whatever program you have assocated *.log files with. You could set that file association to e.g., notepad, or SAS Viewer, or something else to get it to come up in a separate window.

      Sorry not to have a better answer for you.

      Delete
  15. I'm sure this is simple but having an issue. Downloaded the zip file into the respective directory and unzipped. However, in the Sublime 3 GUI when I go to View -> Syntax, I do not see SAS as an option. Is there an additional step I haven't taken? Please help! There is so much potential with this tool that I would love to use :)

    ReplyDelete
    Replies
    1. Sounds like the package is in the wrong 'Packages' dir. With Sublime open, choose 'Browse Packages...' off the Preferences menu. Sublime should open a new explorer window showing the dir where the SAS folder w/the contents of the zip should live.

      HTH,

      -Roy

      Delete
  16. ahh - perfect! For some reason my packages directory was put under the 'AppData/Roaming/...' directory. This is a 64 bit windows 7 machine so if anyone else is having a similar issue try this!

    ReplyDelete
  17. Thank you for this. How can i run only a selection of a scipt? This is possible in normal SAS, but in sublime text 3, I only know how to run the entire script using ctrl+b.

    ReplyDelete
    Replies
    1. You bet! Unfortunately, I do not know how to make that work in Sublime. I have no doubt it's possible, but it's beyond my meager skills at this point.

      Delete
    2. I have work around for it, its not perfect. I have the shortcut key set in SAS ctr+q: output; clear; autoscroll 0; log; clear; autoscroll 0; gsubmit buffer=default;

      So I just copy the code that I want to run, switch to SAS and Ctr+Q

      http://www.tranz.co.uk/PSI2010_PDF_Customization.pdf

      Delete
  18. This comment has been removed by the author.

    ReplyDelete
  19. Great to have a SAS script for sublime -- Thanks!

    ReplyDelete
  20. Just trying out Sublime, having used Uedit and NPP for a long time. I'm missing the obvious in not seeing where to invoke the SAS build/submit feature from within Sublime? I see the python code and the Windows script..both/either of which look like the tools. But do you need to use the New Build System?
    thanks,
    bob mcc...

    ReplyDelete
    Replies
    1. ctrl-b or Tools -> Build should do it.

      Delete
    2. This comment has been removed by the author.

      Delete
  21. those who are interested to learning the sas program this very helpful..learn the sas program to achieve economical benchmark.

    SAS Training in Chennai

    ReplyDelete


  22. Thank you for your post. This is excellent information. It is amazing and wonderful to visit your site.
    microsoft installation and configuration services

    ReplyDelete