Using Notepad++ as your SAS code editor

21

News flash: My favorite SAS code editor is SAS Enterprise Guide. However, my favorite general purpose text editor is Notepad++, and I often find myself using that tool for viewing SAS log files and for making small modifications to SAS programs. Judging from the popularity of this SAS Support Communities discussion, I'm not alone. In this post, I'll share the steps for turning Notepad++ into a more useful home for SAS programs.

You can download Notepad++ for Windows from here -- you can use it for free, no cost. That's one reason that it's one of the first tools that I install on any new PC I get my hands on!

1. Associate SAS files with Notepad++

You accomplish this in the usual way with Windows. In Windows Explorer, right-click (or SHIFT+right-click depending on your setup) on a .SAS file (SAS program), and select Open with...

Open with menu

► You might see Notepad++ in the menu, but don't select it, Instead, select Choose another app.

Choose another app

► In this menu, select Notepad++ and check the "Always use this app" checkbox.

Repeat this step for SAS program logs (.LOG files) and listing output (.LST files) if you want.

2. Run a SAS program from Notepad++

You can add new program actions to the Run menu in Notepad++. Here's how to add a command to run a SAS program, if you have SAS for Windows installed. Note: These steps assume that the SAS program is open in Notepad++ and is saved in a file.

► Select Run... from the Run menu. In the program to run field, enter this command:

"C:\Program Files\SASHome\SASFoundation\9.4\sas.exe" -sysin "$(FULL_CURRENT_PATH)" -log "$(CURRENT_DIRECTORY)\$(NAME_PART).log" -print "$(CURRENT_DIRECTORY)\$(NAME_PART).lst"

all on one line. You might need to adjust the SAS.EXE path for your install. The command options use some Notepad++ environment variables to direct the SAS log and listing output to the same path as the SAS program file.

Click Save (not Run).

Click Save

Optionally, assign a shortcut key to the action, and name it "Run program file in SAS" (or whatever you want). This adds the command to your Run menu.

Run in SAS command

When you select it, Notepad++ will launch SAS, run your program in batch, and direct the output to the same folder where the program is stored.

3. Adding SAS syntax color coding to Notepad++

It's simple to "teach" Notepad++ to recognize the keywords from SAS and other languages. You can download new language definitions files from here -- follow the instructions on the page to have your Notepad++ recognize them. I've created an expanded definition file that includes more SAS keywords (many, many more!) -- you can grab that from my GitHub repo here (be sure to copy/save the "raw" view of the file as XML, then import that into Notepad++).

Here's what SAS code looks like in my Notepad++:

code sample in Notepad++

What else?

I'm sure that some of you have spent more time than I have in creating a souped-up Notepad++ environment, or perhaps you've taken it to another level with other popular editors like Sublime or Vim or UltraEdit. If you have other tips to share, I'd love to hear from you in the comments.

Share

About Author

Chris Hemedinger

Senior Manager, SAS Online Communities

+Chris Hemedinger is the manager of SAS Online Communities. He's also co-author of the popular SAS for Dummies book, author of Custom Tasks for SAS Enterprise Guide using Microsoft .NET, and a frequent participant on the SAS Enterprise Guide discussion forum.

Related Posts

21 Comments

  1. Your language definition fails to import in Notepad++ v7.4.2

    Please update it, I'd be very interested in trying it out, seems more comprehensive than the other ones I've found online so far.

    • Chris Hemedinger
      Chris Hemedinger on

      Hi Alex, I tried this from my home PC (v6.9, which I then updated to v7.4.2) and I was able to import the file with no problems. I re-exported from v7.4.2 -- the file was identical to what I shared on my GitHub.

  2. Richard Thomas on

    I was unable to import into Notepad++ 7.4.2 as well. I tried the manual process (copy to install folder, rename to userDefineLang.xml), but it's not being picked up.

    • Chris Hemedinger
      Chris Hemedinger on

      I've tried this on a few "clean" installs now, and had no problems. I download the UDL file as a local XML (be sure to navigate to "Raw" view first!), then in Notepad++ I go to Language->Define your language. In the big User Defined Language window, I select Import..., then select the XML file I just downloaded. That adds a SAS option the list of "User languages" at the top. When I select "SAS", there are my rules!

  3. Chris,

    I successfully imported your UDL from GitHub into my Notepad 7.4.2. I didn't have any import issues. (For a few years, I was using another SAS UDL, and I replaced it with yours.)

    I also often use Notepad++ in general and sometimes with SAS. I wish Notepad++ would allow running snippets of code and browsing SAS data sets, and I wish the base SAS Enhanced Editor for Windows would notify the user when the source code changes. This feature facilitates switching back and forth between editors.

    • Chris Hemedinger
      Chris Hemedinger on

      Thanks for letting me know! And actually, SAS EG v7.13 supports that last one: it detects when the SAS file has changed and notifies you, and asks you whether you want to reload the file.

    • You might want to take s look at UltraEdit. It is very SAS-friendly and handles your wishes. I've used it for more than 15 years, but I haven't been able to use it for running SAS for a couple years, but I had used it heavily to code and submit jobs to a UNIX machine through its built in FTP feature. It also can poll the.log and .lst files and automatically update the displayed log and output information.

      I've not used Notepad++, but I strive to get UE installed on any system I use. As a contractor, I sometimes have to justify the expense, but that hasn't been a major issue.

  4. shawn skillman on

    Chris,
    This works like a champ, thank you for sharing. I have been a fan of Notepad++ for a while but never explored running SAS code from the editor.

  5. The file import didn't work for me, but as a work around, I was able to get it to work by copying the lines from the RAW view into the userDefineLang.xml file.

    • Chris Hemedinger
      Chris Hemedinger on

      Glad that works -- still at a loss about the import process. I'll look into it. I've heard from others that it worked fine.

  6. Thanks Chris, this is very useful :).

    The SAS XML langage script for NPP (implicitly : NPP running on Windows) you generously provide must be transcoded into ANSI before import,
    downloading the GitHub file with a browser, even the raw version, gives you the XML file encoded with UTF-8, which fails to import, at least for me..
    For this transcoding, I only had to open the file, with NPP itself (v 7.3.3) then select Encoding / Convert to ANSI, then Ctrl+S.

    Notepadd++ is great for editing or even only reading SAS scripts stored locally on Windows or even remotely on Unix/Linux
    when it's also defined as the default script editor for your SFTP client (WinSCP, Filezilla, MobaXterm etc.). I've used it for years.

  7. Thanks, Chris! I ran into problems at step 2. I suspect that Notepad++ cuts off the Run-string after 256 characters. When I shortened it to below 256, cutting "unnecessary" SAS command line options, it worked like a charm.

    • Chris Hemedinger
      Chris Hemedinger on

      Good to know! I suppose you could wrap the elements of this command in a BAT or CMD script to shorten the string for Notepad++.

  8. I think I worked out what is happened with it failing. If you right click on the file and save it what you get is something different to what is expected. You first need to click on the link then change it to raw then save it. Not exactly obvious.

  9. very nice tip :-)
    Beside Enterprise Guide i use Notepad++ for years and was using an other SAS syntax file which also included some small problems. Your syntax file seems to be better!
    I would suggest one small addition: add the %macro and %mend Keywords to the code folding definition. Folding macros in huge programs can be a large time saver.
    Keep up the good work Chris!

    • Chris Hemedinger
      Chris Hemedinger on

      Good suggestion on the code folding -- I think I tried that for a bit, but found a few places where it seemed to break down. However, the extra convenience might be worth the few exceptions...

Leave A Reply

Back to Top