Exporting REDCap data to SAS

Steps to export data to SAS from REDCap:

  1. Click Data Exports, Reports and Stats under Applications on the left-hand side of the screen.

  2. Click Export Data for either “All data” or whichever report you would like to export

  3. Click on “SAS Statistical Software” and click “Export Data” in the bottom right of the pop-up window.

  4. After a brief wait, a window will pop up showing two icons on the right – one that will give a SAS program tailored to import the data and another that serves as the csv file to be imported.  Save both of these files.  Do NOT open the csv file or it could cause unwanted modifications to the data that will cause the import to fail.

  5. Open the created SAS program and edit the csv file macro variable at the top to contain the full filepath and filename of the csv file just saved from REDCap.

  6. Run the import file.  The file will produce a dataset called “redcap” containing the data from the csv file saved from REDCap.

Known issues with REDCap SAS dataset exporting:

  • Never open the csv file provided with the SAS export.  It could cause unwanted modifications to the data that will cause the import to fail.

  • Variable labels (field labels) longer than 256 characters will cause a warning as they are longer than SAS will accept.

  • Non checkbox variable names that at least 30 characters long are truncated to 20 characters with an appended _v_# on the end where the # is a number starting with 0 that increments each time a variable is incremented.

  • Checkbox variables will be truncated if the resulting output variable exceeds 30 characters.  For example, a checkbox variable of 26 characters with code 1 will result in a variable that is 30 characters.  That will not be truncated.  If for the same variable, there is a code of 13, that variable will be 31 characters and will thus be truncated.

  • Radio button, dropdown and text fields that contain values that have a “-“, “+” or leading 0 will need to be modified in the SAS program from a numeric type to character type if the coding cannot be modified in the database.  This will require the informat and format to be changed to a character type (containing $), and the variable will need to have a $ after it in the input statement to indicate to SAS it is importing a character variable. If this is not done, the variable value will resort to “#NAME?” in the export file.

  • Radio button, dropdown and text fields that contain values that could be misconstrued as dates may be exported as dates. For example, the value “1-19” will export as “19-Jan.” The SAS program will need to be modified from a date type to character type. This will require the informat and format to be changed to a character type (containing $), and the variable will need to have a $ after it in the input statement to indicate to SAS it is importing a character variable.

Variable renaming examples:

  • A variable with the name thisvariablenameiswaywaytoolong is 31 characters and would be truncated to something similar to this: thisvariablenameisway_v_#

  • A checkbox variable with name thisvariablenameistoolong and code 1 would show up as thisvariablenameistoolong___1 since the result is 29 characters and okay for REDCap exports

  • A checkbox variable with name thisvariablenameistoolong and code 9999 would show up as thisvariablenameisto_v_# because the resulting variable name would have been thisvariablenameistoolong___9999 which is 32 characters – exceeding the character limit for exports of 30 characters.  This CAN happen for the same checkbox variable for different codes if the codes are longer for certain choices as seen with this bullet point and the previous bullet point.