BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Mounika2
Calcite | Level 5

output-

pt     element          Start_date      end_date

101 screening        2017-02-10   2017-02-24
101 randomization 2017-02-24   2017-03-05
101 treatment        2017-03-05   2017-09 -23
101 followup          2017-09-23   2017-02-12

102 screening        2017-02-12   2017-02-22
102 randomization 2017-02-22   2017-03-10
102 treatment        2017-03-10   2017-09-20
102 followup          2017-09-20   2017-09-20

 

 data raw (rename= (visit= ELEMENT));
input pt visit$9. STDT: is8601da.;
format STDT is8601da.;
datalines;
101 screening        2017-02-10
101 randomization 2017-02-24
101 treatment        2017-03-05
101 followup          2017-09-23 

102 screening        2017-02-12   
102 randomization 2017-02-22   
102 treatment        2017-03-10   
102 followup          2017-09-20   
run;

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

I think this is what you want

 

data raw (rename= (visit= ELEMENT));
input pt visit :$13. STDT: is8601da.;
format STDT is8601da.;
datalines;
101 screening 2017-02-10
101 randomization 2017-02-24
101 treatment 2017-03-05
101 followup 2017-09-23 
102 screening 2017-02-12 
102 randomization 2017-02-22 
102 treatment 2017-03-10 
102 followup 2017-09-20 
run;

data want;
   merge raw(rename=STDT=start_date) raw(firstobs=2 rename=STDT=end_date keep=STDT);
   if ELEMENT='followup' then end_date=start_date;
run;

View solution in original post

2 REPLIES 2
PeterClemmensen
Tourmaline | Level 20

Are you sure this is the output you want? As I see it, you fetch the Start_Date of the screening for pt 102 as the end_date for the followup for pt 101? I don't think this is desirable?

PeterClemmensen
Tourmaline | Level 20

I think this is what you want

 

data raw (rename= (visit= ELEMENT));
input pt visit :$13. STDT: is8601da.;
format STDT is8601da.;
datalines;
101 screening 2017-02-10
101 randomization 2017-02-24
101 treatment 2017-03-05
101 followup 2017-09-23 
102 screening 2017-02-12 
102 randomization 2017-02-22 
102 treatment 2017-03-10 
102 followup 2017-09-20 
run;

data want;
   merge raw(rename=STDT=start_date) raw(firstobs=2 rename=STDT=end_date keep=STDT);
   if ELEMENT='followup' then end_date=start_date;
run;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 854 views
  • 0 likes
  • 2 in conversation