SAS (Base SAS)+
*==============================================================================;
* Write SAS Transport Files (.xpt)
*==============================================================================;
*------------------------------------------------------------------------------;
* Step 1 - Create a small ADSL dataset with labels
*------------------------------------------------------------------------------;
data adsl;
length USUBJID $20 SITEID $4 SEX $1 TRT01P $20;
label USUBJID = "Unique Subject Identifier"
SITEID = "Study Site Identifier"
SEX = "Sex"
AGE = "Age in Years"
TRT01P = "Planned Treatment for Period 01";
infile datalines dlm='|' dsd missover;
input USUBJID : $20. SITEID : $4. SEX : $1. AGE : best32. TRT01P : $20.;
datalines;
ABC-001-001|001|M|45|Placebo
ABC-001-002|001|F|52|Drug A
ABC-002-003|002|M|38|Drug B
ABC-002-004|002|F|61|Placebo
ABC-003-005|003|M|55|Drug A
;
run;
*------------------------------------------------------------------------------;
* Step 2 - Write the .xpt file using LIBNAME XPORT + PROC COPY
*------------------------------------------------------------------------------;
libname xptout xport "C:\clinical\output\adsl.xpt";
proc copy in=work out=xptout;
select adsl;
run;
libname xptout clear;
*------------------------------------------------------------------------------;
* Step 3 - Verify by reading it back
*------------------------------------------------------------------------------;
libname xptin xport "C:\clinical\output\adsl.xpt";
proc contents data=xptin.adsl;
run;
proc print data=xptin.adsl;
run;
libname xptin clear;
*------------------------------------------------------------------------------;
* Alternative - PROC CPORT (creates a different binary format)
*------------------------------------------------------------------------------;
* proc cport data=adsl file="C:\clinical\output\adsl_cport.xpt";
* run;
* Note: PROC CPORT creates a SAS transport file that only SAS can read.
* For FDA submissions, use the LIBNAME XPORT method above.;- We first build a small ADSL dataset with labels assigned, since labels are preserved in the transport file and required for submissions.
- To write the
.xptfile, we assign aLIBNAMEwith theXPORTengine pointing to the output file path. PROC COPYtransfers the dataset from WORK to the XPORT library —SELECT adsl;tells SAS which dataset to write.- We clear the libname after writing with
LIBNAME xptout CLEAR;to release the file handle. - To verify the output, we assign a new read-only libname to the
.xptfile and runPROC CONTENTSandPROC PRINT. PROC CPORTis an alternative, but it creates a proprietary format that only SAS can read — FDA reviewers expect the standard XPORT format.- Before writing, we confirm that all variable names are 8 characters or fewer and all labels are 200 characters or fewer — the V5 transport format enforces these limits.