data SV (RENAME=(VISIT=TERM));
input PT VISIT$9. STDT: YYMMDD8.;
format STDT is8601da.;
datalines;
101 screening 2017-02-10
102 screening 2017-02-12
103 screening 2017-02-16
104 screening 2017-02-11
run;
data RI;
input PT TERM$13. STDT: is8601da.;
format STDT is8601da.;
datalines;
101 randomization 2017-02-23
102 randomization 2017-02-22
103 randomization 2017-02-20
104 randomization 2017-02-21
run;
data DM (RENAME=(ACTARM=TERM));
input PT ACTARM$ RFSTDTC is8601da.;
format RFSTDTC is8601da.;
datalines;
101 drugA 2017-03-05
102 drugB 2017-03-10
103 drugA 2017-03-06
104 drugB 2017-03-01
RUN;
DATA DS;
INPUT PT TERM$ STDT IS8601DA.;
FORMAT STDT IS8601DA.;
DATALINES;
101 complete 2017-09-23
102 complete 2017-09-20
103 complete 2017-09-24
104 complete 2017-04-22
RUN;
i got the following output by combining the above datasets;
data want;
set ri sv dm;
if STDT= " " then STDT=RFSTDTC;
run;
proc sort data=want;
by pt term;
run;
output
Pt TERM STDTC RFSTDTC
101 screening 2017-02-10
101 randomization 2017-02-23
101 drugA 2017-03-05 2017-03-05
101 complete 2017-09-23
102 screening 2017-02-12
102 randomization 2017-02-22
102 drugB 2017-03-10 2017-03-10
102 complete 2017-09-20
103 screening 2017-02-16
103 randomization 2017-02-20
103 drugA 2017-03-06 2017-03-06
103 complete 2017-09-24
104 screening 2017-02-11
104 randomization 2017-02-21
104 drugB 2017-03-01 2017-03-01
104 complete 2017-04-22
what i want is
Pt TERM STDTC RFSTDTC
101 screening 2017-02-10 2017-03-05
101 randomization 2017-02-23 2017-03-05
101 drugA 2017-03-05 2017-03-05
101 complete 2017-09-23 2017-03-05
102 screening 2017-02-12 2017-03-10
102 randomization 2017-02-22 2017-03-10
102 drugB 2017-03-10 2017-03-10
102 complete 2017-09-20 2017-03-10
103 screening 2017-02-16 2017-03-06
103 randomization 2017-02-20 2017-03-06
103 drugA 2017-03-06 2017-03-06
103 complete 2017-09-24 2017-03-06
104 screening 2017-02-11 2017-03-01
104 randomization 2017-02-21 2017-03-01
104 drugB 2017-03-01 2017-03-01
104 complete 2017-04-22 2017-03-01
Please try the below code on existing dataset
data want2;
merge want(drop=RFSTDTC) dm(keep=pt RFSTDTC);
by pt;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.