Trial Visits (TV) dataset in the Trial Design model describe the planned visits of the study, but it is also necessary to collect corresponding actual data in Subject Visits (SV) dataset. The subject visits domain consolidates information about the timing of subject visits. This means that we have to take all other domains containing visit variables into consideration. The common approach is to open all source dataset and see if visit variables are included. This process is time consuming. Is there an easier method? This post will take library TEST as an example and make an explanation.

Get all timing variables within entire library

Suppose that all timing variables contain suffix _DTS, below ‘where’ statement can be used to filter all timing variables from TEST library.

Click here to hide/show code


proc contents data=test._all_ noprint
out = dat(where=(index(strip(name), “_DTS”)));
quit;

By running above code, you can get a dataset similar to that in following figure. Only two variables – MEMNAME and NAME – are useful given our purpose. MEMNAME incudes dataset names while NAME contains corresponding variable names from datasets within entire library.

Put all timing variables from same dataset together

We can put all variables from same dataset together and leave only observation for each source dataset.

Click here to hide/show code


proc sort data=dat; by memname name; run;
data dat(keep=memname var);
length var $500.;
retain var;
set dat;
by memname name;
if first.memname then var = strip(name);
if first.memname = 0 then var = strip(var)||” “||strip(name);
if last.memname;
run;

Here is the result output. You can see that AEENDAT_DTS and AESTDAT_DTS have been placed together and there is only one row to put information about dataset RD_AE.

Create macro variables for dataset name, variable list & total number of datasets for entire library

Click here to hide/show code


data _null_;
set dat end=eof;
call symputx(“dat”||strip(put(_n_,best.)), strip(memname));
call symputx(“var”||strip(put(_n_,best.)), strip(var));
if eof then call symputx(“totn”,strip(put(_n_,best.)));
run;

Set together all datasets within TEST library and create a new dataset named TEST

By using macro variables that were just created, we can loop through all datasets and keep timing variables, subject identifier number and visit variable (VISIT in our case). Domains like AE are visit independent and should not be taken into consideration. We can use conditions like that – VISIT not in (“LOGS”, “ENR”) – in below to remove those domains. You can customize this for your study. After clearing all datasets, we can still use do statement to set all datasets together and then remove all of them from work library.

Click here to hide/show code


%macro setall;
%do i = 1 %to &totn;
data &&dat&i;
length source $200.;
set test.&&dat&i;
source = “test.&&dat&i”;
if visit not in (“LOGS”, “ENR”);
keep subject visit source &&var&i;
run;
%end;

data test;
set %do i = 1 %to &totn;
&&dat&i
%end;;
run;

proc datasets lib=work;
delete %do i = 1 %to &totn;
&&dat&i
%end; dat;
quit;
%mend;

%setall;

Create macro variables for timing variable list of TEST dataset

Click here to hide/show code


ods exclude all;
ods output Variables = var(where=(index(variable,”_DTS”)));
proc contents data=test; run;
ods output close;
ods exclude none;

proc sql noprint;
select variable into: varlist separated by ” ” from var;
select count(*) into: nobs from var;
quit;

Consolidate all timing information into one variable VISITDTC

Click here to hide/show code


data test(keep = subject visit visitdtc source);
length visitdtc $20.
set test;

array col{&nobs} &varlist;
do i = 1 to &nobs;
if col{i} ne “” then do;
visitdtc = col{i};
output;
end;
end;
run;


Here is to show you final output. So far, we have put all timing information in one variable. And now you can move on to use VISITDTC to compute SVSTDTC and SVENDTC based on rules in your SDTM specification.

Note:

This post illustrated on how to get variables from entire library or only one dataset using PROC CONTENTS.