Understanding Code Snippets

Why Use Code Snippets?

Code snippets enable you to quickly insert SAS code into your program and customize it to meet your needs. SAS Web Editor is shipped with several code snippets. You can also create your own snippets and create favorites.
Note: If you are running SAS Web Editor 2.5 on the iPad, use the Insert Sample Code feature to access the sample code snippets.
Snippet Name
Description
Data
Import CSV File
The Import CSV File snippet enables you to import a comma-separated file and write the output to a SAS data set.
Import Excel File
The Import Excel File snippet enables you to import a Microsoft Excel file and write the output to a SAS data set.
Generate a CSV File
The Generate a CSV File snippet enables you to export SAS data as a comma-separated text file.
Generate an XML File
The Generate an XML File snippet enables you to export SAS data as an XML file that you can view in your web browser.
Graph
Note: For more information about the SGPLOT, SGPANEL, and SGSCATTER procedures, see SAS ODS Graphics: Procedures Guide.
Histogram Plot
The Histogram Plot snippet uses the HISTOGRAM statement in the SGPLOT procedure. This code snippet produces a histogram with two density plots. In this snippet, one density plot uses a normal density estimate and the other density plot uses a kernel density estimate.
Fit Plot
The Fit Plot snippet uses the REG statement in the SGPLOT procedure. This code snippet produces regression plot with a quadratic fit and includes confidence limits.
VBox Plot
The VBox Plot snippet uses the VBOX statement in the SGPLOT procedure. A box plot summarizes the data and indicates the median, upper and lower quartiles, and minimum and maximum values. The plot provides a quick visual summary that easily shows center, spread, range, and any outliers. The SGPLOT and the SGPANEL procedures have separate statements for creating horizontal and vertical box plots.
Dot Plot
The Dot Plot snippet uses the DOT statement in the SGPLOT procedure. Dot plots summarize horizontally the values of a category variable. By default, each dot represents the frequency for each value of the category variable.
HighLow Plot
The HighLow Plot snippet uses the HIGHLOW statement in the SGPLOT procedure. High-low charts show how several values of one variable relate to one value of another variable. Typically, each variable value on the horizontal axis has several corresponding values on the vertical axis.
HBar Plot
The HBar Plot snippet uses the HBAR statement in the SGPLOT procedure. This code snippet creates a horizontal bar chart that summarizes the values of a category variable.
Box Panel
The Box Panel snippet uses the VBOX statement in the SGPANEL procedure and enables you to create multiple box plots.
Bar Panel
The Bar Panel snippet uses the VBAR statement in the SGPANEL procedure and enables you to create multiple bar charts.
Comparative Scatter Plot
The Comparative Scatter Plot snippet uses the COMPARE statement in the SGSCATTER procedure. This code snippet creates a comparative panel of scatter plots with shared axes.
Scatter Plot Matrix
The Scatter Plot Matrix snippet uses the MATRIX statement in the SGSCATTER procedure. This code snippet creates a scatter plot matrix.
Macro
SAS Macro
The SAS Macro snippet provides a template for creating a SAS macro program. For more information, see SAS Macro Language: Reference.
Descriptive
PROC SQL
The PROC SQL snippet provides a template for writing SQL queries. For more information, see SAS SQL Procedure User's Guide.
Custom ODS Output
The Custom ODS Output snippet provides a template for creating HTML, PDF, and RTF output using the SAS Output Delivery System. For more information, see SAS Output Delivery System: User's Guide.
To add a snippet to your list of favorites, select the snippet name and click Favorite button.

Create a Code Snippet

To create your own snippet:
  1. Open your .sas file in the SAS Web Editor and select the code that you want to save as a snippet.
  2. In the program tab, click Add Snippet button. The Add to My Snippets dialog box appears.
  3. Enter a name for the snippet and click Save.
This snippet is now available from the My Snippets folder.

How to Insert a Code Snippet

To include a code snippet in your program:
  1. Select the location in your program where you want to insert the snippet.
  2. In the navigation pane, open the Tasks and Snippets section.
  3. You can add the snippet to your program in these ways:
    • use a drag-and-drop operation to move the snippet
    • double-click the name of the snippet
    • right-click the name of the snippet and select Insert
    Code for Importing an Excel File Inserted into a Program