Generated SAS Code¶
Generated Programs¶
The YES3 Exporter II SAS code generator will add 3 SAS programs to the export payload. These are described in the table below. All programs are designed to be run as-is. The ground rule for as-is execution is that the programs and the exported datasheet must reside in the same folder. The dataset and format catalog are written to the folder specified in the LIBREF export setting.
| SAS program | description |
|---|---|
| [dsname]_input.sas | Builds and conditionally saves a SAS dataset based on the export specifications. If any error is encountered, the permanent dataset is not written. |
| [dsname]_fmtlib_create.sas | Creates or updates a permanent format catalog (e.g., formats.sas7bcat) from the value sets of the variables in the export. See the note below on how the YES3 Exporter II manages formats. |
| [dsname]_fmtlib_assign.sas | Assigns formats to the SAS dataset created from the export. This program can also be used as a resource for copying and pasting format assignment code into reports, etc. |
How SAS formats are managed¶
SAS formats are shared not only between the variables in the current export, but between variables across all exports for a REDCap project. In this way, the format catalog is as efficient as possible. This is accomplished by a project-wide "value set registry" that catalogs every unique valueset, as stored in redcap_metadata.element_enum, from among all fields used for any export.
SAS variable names¶
The YES3 SAS Code Generator ensures that SAS variables adhere to SAS requirements, namely
- Variable names must be 1 to 32 characters long
- Variable names must begin with a letter (A-Z, a-z) or underscore (_)
- Variable names can contain only letters, digits (0-9), and underscores
- Variable names are case-insensitive (SAS treats uppercase and lowercase as the same)
- Variable names cannot be SAS reserved words (e.g., DATA, SET, IF, THEN, etc.)
- Variable names cannot contain spaces or special characters other than underscores
The most challenging of these is the length restriction, especially for horizontal layouts. In the most complex scenario, the Exporter-generated data dictionary column name will include:
- An event prefix followed by an underscore,
- The REDCap field name, and
- A checkbox option value preceded by three underscores.
For example, a data dictionary column name might conceivably be:
Where foll06m is the event prefix and zzzz is one of the option values for this hypothetical checkbox field.
At 51 characters long, this is way out of bounds for a SAS variable name.
The SAS variable name algorithm, as enforced by the function Yes3Fn::sanitizeForSASVarName() will:
- Preserve any prefix (leading characters ending in an underscore),
- Preserve any suffix (trailing characters beginning with an underscore),
- Retain as much of the REDCap field name as possible while ensuring a unique variable name.
The algorithm ensures uniqueness by inserting a 3-digit number at the end of the field name segment of the computed variable name.
For our example, the computed SAS variable name might be:
Whenever the SAS variable name does not match the REDCap field name, the generated SAS INPUT code will indicate, by way of a comment, the full name of the underlying REDCap field. For example:
ATTRIB
partid
LENGTH = $9
LABEL = "Participant ID"
INFORMAT = $9.
redcap_data_access_group_id
LENGTH = 4
LABEL = "REDCap Data Access Group Id"
redcap_data_access_group
LENGTH = $64
LABEL = "REDCap Data Access Group Name"
INFORMAT = $64.
...
foll06m_really_really_0123___zzzz
LENGTH = 4
LABEL = "My unfortunately named multiselect checkbox field"
INFORMAT = 1.
/* source REDCap field = [really_really_long_redcap_field_name] */
...
;
Note: checkbox fields, when exported using the 'multiple column' export setting, will always take on the value of 1 if checked, and blank (missing) if unchecked. Hence the numeric variable type in this example.
This example highlights the importance of parsimony in event prefixes, REDCap field names, and checkbox option values.
Running SAS in Batch Mode¶
The exported SAS code will run either interactively or in batch mode. In general, interactive mode is better for testing, and explorations and batch mode is preferred for operations. An example of a Windows command (batch) script for running SAS in batch mode is given in the Technical Reference, in the Datamart Considerations appendix.