Skip to content

Commit

Permalink
Closes #3. SAS now handles instrument status fields
Browse files Browse the repository at this point in the history
  • Loading branch information
Egeler, Paul W committed Jun 5, 2018
1 parent 57a0538 commit 3f891fc
Showing 1 changed file with 32 additions and 4 deletions.
36 changes: 32 additions & 4 deletions SAS/REDCap_split.sas
Expand Up @@ -49,9 +49,8 @@


%MACRO REDCAP_SPLIT(
DATA_DICTIONARY = REDCAP_DATA_DICTIONARY /* The name of the SAS dataset of the data dictionary */,
DATA_SET = REDCAP /* The name of the SAS dataset created by REDCap */,
KEY = RECORD_ID /* Variable that links base table with other tables */
DATA_DICTIONARY = REDCAP_DATA_DICTIONARY /* The name of the SAS dataset of the data dictionary */
);

/* Remove formatting from repeat instrument field */
Expand Down Expand Up @@ -83,13 +82,23 @@

%IF &N_SUBTABLES GT 0 %THEN %DO;

/* Make a list of fields and their associated forms based on data dictionary */
/* Get information on the variables in the dataset */
PROC CONTENTS
DATA = &DATA_SET.
OUT = REDCAP_VARNAMES(KEEP=NAME)
OUT = REDCAP_VARNAMES(KEEP=NAME VARNUM)
NOPRINT;
RUN;

/* Find the key that links the base table to child tables */
DATA _NULL_;
SET REDCAP_VARNAMES;
IF VARNUM EQ 1 THEN DO;
CALL SYMPUT("KEY", NAME);
STOP;
END;
RUN;

/* Make a list of fields and their associated forms based on data dictionary */
DATA REDCAP_FIELDS(KEEP=VAR_NAME FORM_NAME);
SET &DATA_DICTIONARY.;
IF FIELD_TYPE EQ "checkbox" THEN DO;
Expand All @@ -104,6 +113,20 @@
END;
ELSE OUTPUT;
RUN;

/* Add instrument status fields to list of fields */
PROC SQL;

CREATE TABLE REDCAP_INSTRUMENT_STATUS_FIELDS AS
SELECT DISTINCT TRIM(FORM_NAME)!!"_complete" AS VAR_NAME LENGTH=200, FORM_NAME
FROM REDCAP_DATA_DICTIONARY;

QUIT;

PROC APPEND
BASE=REDCAP_FIELDS
DATA=REDCAP_INSTRUMENT_STATUS_FIELDS;
RUN;

/* Sort out the field names */
PROC SQL NOPRINT;
Expand Down Expand Up @@ -151,6 +174,11 @@

%END;

/* Clean up temporary datasets */
PROC DATASETS MEMTYPE=DATA LIBRARY=WORK NOLIST;
DELETE REDCAP_FIELDS REDCAP_VARNAMES REDCAP_INSTRUMENT_STATUS_FIELDS;
RUN;

%END;

%ELSE %DO;
Expand Down

0 comments on commit 3f891fc

Please sign in to comment.