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-12
102 randomization 2017-02-12   2017-02-16
103 treatment        2017-02-16   2017-02 -18
104 followup          2017-02-18   2017-02-18

 

 data raw (rename= (visit= ELEMENT));
input pt visit$9. STDT: is8601da.;
format STDT is8601da.;
datalines;
101 screening        2017-02-10
102 randomization 2017-02-12
103 treatment        2017-02-16
104 followup          2017-02-18
run;

 

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20
 data raw (rename= (visit= ELEMENT));
input pt visit :$13. STDT: is8601da.;
format STDT is8601da.;
datalines;
101 screening 2017-02-10
102 randomization 2017-02-12
103 treatment 2017-02-16
104 followup 2017-02-18
run;

data want;
   merge raw(rename=STDT=start_date) raw(firstobs=2 rename=STDT=end_date keep=STDT) end=lr;
   if lr then end_date=start_date;
run;

View solution in original post

7 REPLIES 7
PeterClemmensen
Tourmaline | Level 20
 data raw (rename= (visit= ELEMENT));
input pt visit :$13. STDT: is8601da.;
format STDT is8601da.;
datalines;
101 screening 2017-02-10
102 randomization 2017-02-12
103 treatment 2017-02-16
104 followup 2017-02-18
run;

data want;
   merge raw(rename=STDT=start_date) raw(firstobs=2 rename=STDT=end_date keep=STDT) end=lr;
   if lr then end_date=start_date;
run;
Mounika2
Calcite | Level 5
What does end= lr mean
PeterClemmensen
Tourmaline | Level 20

The end=lr option means that I create a temporary variable lr which is equal to 1 on the last observation of the data set and zero otherwise. I use this variable to set the appropriate end_date on the last observation, which should be the same as start_date as I see it. Does that make sense?

Mounika2
Calcite | Level 5
Yes.
Thank you 😊
PeterClemmensen
Tourmaline | Level 20

No problem 🙂 Glad you found your answer.

Mounika2
Calcite | Level 5

here it is not displaying screening and followup is shown twice. i want only followup start and end dates to be equal and for the rest end date must be the second value of start date

PeterClemmensen
Tourmaline | Level 20

See my answer in your other thread

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
  • 7 replies
  • 1687 views
  • 0 likes
  • 2 in conversation