SAS Snippets

Snippets Introduction

Snippets are pieces of code that perform some action for you. Typically, they enable you to configure a piece of code and then insert it, saving you from a lot of typing. Snippets can also perform actions for you, like searching a SAS Metadata server. Snippets are a robust form of the Eclipse Editor snippets.

Displaying the SAS Snippets

To display the SAS snippets, follow these steps:
  1. Select Windowthen selectShow Viewthen selectOther.
  2. Expand General.
  3. Select Snippets and then click OK.
  4. Inside the Snippets tab, click SAS Snippets.

Inserting a SAS Snippet

To insert a snippet, follow these steps:
  1. Place your cursor inside a non-static method body where you want to insert the snippet.
  2. Double click on the snippet that you want to insert (or right-click and select Insert).
  3. Configure the variables used in the snippet.
    Variables in the snippet are either declared at the top of the snippet, or are replaced by variables that already exist in the code.
    Configure Snippet dialog box
    The Initialization Code field for each variable defines how the variable is assigned. The Initialization Code can be set one of three ways:
    • An illegal value that will not compile so that you are forced to fix it (for example, ENTER_HOST_NAME_HERE).
    • Arbitrary text that you enter.
      You can enter any text, method call, or other complex expression for the Initialization Code. If entering a string, include the appropriate quotation marks and escape characters.
    • A variable from your code.
      The list of values is populated with all of the variables in scope that are compatible with this variable type. If you select one of these variables, the declaration at the top of the snippet is removed and the variable that you have selected is used throughout the snippet.
  4. Choose whether to Surround generated code with try/finally. This option encloses the generated code in a try/finally block. This is useful if you want to handle the declared exceptions in the current method.
  5. Click Insert.
    The snippet code is added at the cursor location and the necessary import statements are added to the top of your source file. Inserted type references are fully qualified if they would conflict with an existing import.