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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.