This repository documents a SAS code snippet that imports the flat REDCap database into a SAS readable dataset.
One can utilize the built-in export functions within REDCap to create a SAS-readable dataset, but this requires many manual manipulations and does not lend well to automation. Utilizing the API will allow a user to programmatically retrieve data from their REDCap database and use the data in SAS without accessing the REDCap web interface.
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.
- REDCap database
- SAS installed on system
- Your unique API token provided by REDCap (do not share this with anyone!)
- A directory to house all files created by importer
- Download a copy of the enclosed .sas file to the directory where you would like to save the data and resulting SAS datasets. Make sure to modify the filenames and directories within the program to locations of your choosing.
*** Text file for API parameters that define the request sent to REDCap API will be created in a DATA step ***;
filename my_in "your-directory\api_parameter.txt";
*** .CSV output file for the exported data ***;
filename my_out "your-directory\redcap_data.csv";
*** Output file of PROC HTTP status information returned from REDCap API (this is optional) ***;
filename status "your-directory\redcap_status.txt";
- Copy your API token into the required location for this SAS program.
*** Project- and user-specific token obtained from REDCap ***;
%let mytoken = ######; /*replace this with your token*/
- Replace the URL with the url for your REDCap instance.
url ="https://poa-redcap.med.yale.edu/api/" /*this can be modified to accomodate other servers/instances*/
- Download the SAS code from the REDCap web application and paste into the SAS program, replacing the existing template.
%macro removeOldFile(bye); %if %sysfunc(exist(&bye.)) %then %do; proc delete data=&bye.; run; %end; %mend removeOldFile; %removeOldFile(work.redcap); data REDCAP; %let _EFIERR_ = 0;
infile my_out delimiter = ',' MISSOVER DSD lrecl=32767 firstobs=2 ;
informat ... ;
======================================;
Code continues;
======================================;
format ...;
run;
- Make the required modifications to the copied portion of the code.
*** Change INFILE name to data named in PROC HTTP OUT =, in this case my_out ***;
*** Change FIRSTOBS=1 to FIRSTOBS=2 to indicate that a header row exists ***;
*** Id desired, comment out or delete proc contents and run statement in middle of importer to prevent table being printed. ***;
- SAS
- REDCap API
- Sumon Chattopadhyay - Initial work - REDCap@Yale
This project is licensed under the MIT License - see the LICENSE file for details
This code snippet is adapted from the following publication:
Sarah Worley, Dongsheng Yang, SAS and REDCap API: Efficient and Reproducible Data Import and Export, MWSUG-2013-RX02 (https://www.mwsug.org/proceedings/2013/RX/MWSUG-2013-RX02.pdf)