/*------------------------------------------------------------*
* program:     cdisc83.sas                                    *
* Description: Case #83. RELREC Key For RELREC domains, this identifies Related Records*
*              domain reference to a key variable that isn't defined in the target domain.*
* By:          Sy Truong, 10/14/2009                          *
*-------------------------------------------------------------*/

libname datalib '../data';
options nofmterr;

data datalib.RELREC (label="Adverse Events");
attrib STUDYID label="Study Identifier" length=$100; 
attrib RDOMAIN label="Related Domain Abbreviation" length=$100; 
attrib USUBJID label="Unique Subject Identifier" length=$100; 
attrib IDVAR label="Identifier Variable" length=$100; 
attrib IDVARVAL label="Identifier Variable Value" length=$100; 
attrib RELTYPE label="Relationship Type" length=$100; 
attrib RELID label="Relationship Identifier" length=$100; 

 STUDYID  ="001"; 
 RDOMAIN   ="DM";
 USUBJID  ="001";
 IDVAR    ="BRTHDTC";
 IDVARVAL  ="001";
 RELTYPE  ="ONE";
 RELID   ="CURLIB.DM";
 output;

 STUDYID  ="001"; 
 RDOMAIN   ="DM";
 USUBJID  ="002";
 IDVAR    ="BRTHDTC";
 IDVARVAL  ="001";
 RELTYPE  ="ONE";
 RELID   ="CURLIB.DM";
 output;

 STUDYID  ="001"; 
 RDOMAIN   ="FR";
 USUBJID  ="003";
 IDVAR    ="BRTHDTC";
 IDVARVAL  ="001";
 RELTYPE  ="ONE";
 RELID   ="CURLIB.DM";
 output;
run;

data datalib.dm(label="Demographics");
attrib STUDYID   label="Study Identifier" length=$100;
attrib DOMAIN  	 label="Domain Abbreviation" length=$100;
attrib USUBJID   label="Unique Subject Identifier" length=$100;
attrib SUBJID  	 label="Subject Identifier for the Study" length=$100;
attrib RFSTDTC   label="Subject Reference Start Date/Time" length=$100;
attrib RFENDTC   label="Subject Reference End Date/Time" length=$100;
attrib SITEID  	 label="Study Site Identifier" length=$100;
attrib INVID  	 label="Investigator Identifier" length=$100;
attrib INVNAM  	 label="Investigator Name" length=$100;
attrib AGE  	 label="Age" length=8;
attrib AGEU  	 label="Age Units" length=$100;
attrib SEX  	 label="Sex" length=$100;
attrib RACE  	 label="Race" length=$100;
attrib ETHNIC  	 label="Ethnicity" length=$100; 
attrib ARMCD  	 label="Planned Arm Code" length=$100;
attrib ARM  	 label="Description of Planned Arm" length=$100;
attrib COUNTRY   label="Country" length=$100;
attrib DMDTC  	 label="Date/Time of Collection" length=$100;
attrib DMDY  	 label="Study Day of Collection" length=8;
STUDYID ='test'; 
DOMAIN='test';USUBJID='test';  SUBJID  ='test';RFSTDTC  ='test';RFENDTC  ='test';SITEID  ='test';INVID  ='test';INVNAM  ='test';AGE  =50;
AGEU  ='test';SEX  ='test';RACE  ='test';ETHNIC  ='test';ARMCD  ='test';ARM  ='test';COUNTRY  ='test';DMDTC  ='test';DMDY  =123;
output;
STUDYID ='test';
DOMAIN='test';USUBJID='test';  SUBJID  ='test';RFSTDTC  ='test';RFENDTC  ='test';SITEID  ='test';INVID  ='test';INVNAM  ='test';AGE  =50;
AGEU  ='test';SEX  ='test';RACE  ='test';ETHNIC  ='test';ARMCD  ='SCRNFAIL';ARM  ='test';COUNTRY  ='test';DMDTC  ='test';DMDY  =123;
output;
STUDYID ='test';
DOMAIN='test';USUBJID='test';  SUBJID  ='test';RFSTDTC  ='test';RFENDTC  ='test';SITEID  ='test';INVID  ='test';INVNAM  ='test';AGE  =50;
AGEU  ='test';SEX  ='test';RACE  ='test';ETHNIC  ='test';ARMCD  ='test';ARM  ='test';COUNTRY  ='test';DMDTC  ='test';DMDY  =123;
output;
STUDYID ='test';
DOMAIN='test';USUBJID='test';  SUBJID  ='test';RFSTDTC  ='test';RFENDTC  ='test';SITEID  ='test';INVID  ='test';INVNAM  ='test';AGE  =50;
AGEU  ='test';SEX  ='test';RACE  ='test';ETHNIC  ='test';ARMCD  ='test';ARM  ='Screen Failure';COUNTRY  ='test';DMDTC  ='test';DMDY  =123;
output;
STUDYID ='test';
DOMAIN='test';USUBJID='test';  SUBJID  ='test';RFSTDTC  ='test';RFENDTC  ='test';SITEID  ='test';INVID  ='test';INVNAM  ='test';AGE  =50;
AGEU  ='test';SEX  ='test';RACE  ='test';ETHNIC  ='test';ARMCD  ='test';ARM  ='test';COUNTRY  ='test';DMDTC  ='test';DMDY  =123;
output;
STUDYID ='test';
DOMAIN='test';USUBJID='test';  SUBJID  ='test';RFSTDTC  ='test';RFENDTC  ='test';SITEID  ='test';INVID  ='test';INVNAM  ='test';AGE  =50;
AGEU  ='test';SEX  ='test';RACE  ='test';ETHNIC  ='test';ARMCD  ='SCRNFAIL';ARM  ='Screen Failure';COUNTRY  ='test';DMDTC  ='test';DMDY  =123;
output;
run;

/*----------------------------------------------------*
* Program: cdisc.sas
* Path: C:\Program Files\SAS 9.2\SASFoundation\9.2
* Description: Verify SAS datasets against CDISC standards
* By: Jeanny Huynhh, %cdisc, 10/05/2009,  2:55:15 pm
*-----------------------------------------------------*/
*** Apply the CDISC check ***;
%cdisc (datlib=datalib,
        datname= RELREC);
