BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Jack2012
Obsidian | Level 7

HI All, 

I think this is q simple question, but uncertain how to work it out.  

So far as I recall, maybe use RETAIN, but have no clue on.  Hope someone can favor me. 

Thank you. 

Jack

/*-------------------------------------------------------*/

Below picture is the dummy data, I would like to record the same dose lifecycle trajactory. 

what I want to have is:

exdose  subjid  dose_st_dt   dose_en_dt

110mg  615010 2021-12-10  2022-01-19

0mg      615010 2022-01-20  2022-01-23 

110mg   615010 2022-01-24  2022-02-15

0mg      615010 2022-02-16   2022-02-22

55mg    615010 2022-02-23   2022-03-29

 

 

Jack2012_0-1652286050790.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

From now on, please do not provide data as screen captures, we can't write programs to use screen capture data. Instead, we need data provided as SAS data step code which you can type in yourself, or via these instructions.

 

Also, it would help if you provided a clear description of how the final table is calculated from the input data. Don't make us guess, sometimes we get it wrong. 

 

So, without actual data, my code is UNTESTED. It is also based on my guesses as to what the method is, and maybe I guessed wrong.

 

data intermediate;
    set have;
    prev_exdose=lag(exdose);
    prev_subj=lag(subjid);
    if (exdose^=prev_exdose and subjid=prev_subj) or subjid^=prev_subj then group+1;
run;
proc summary data=intermediate nway;
    class group;
    id exdose subjid;
    var dose_st_dt dose_en_dt;
    output out=want min(dose_st_date)= max(dose_en_dt)=;
run;
--
Paige Miller

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

From now on, please do not provide data as screen captures, we can't write programs to use screen capture data. Instead, we need data provided as SAS data step code which you can type in yourself, or via these instructions.

 

Also, it would help if you provided a clear description of how the final table is calculated from the input data. Don't make us guess, sometimes we get it wrong. 

 

So, without actual data, my code is UNTESTED. It is also based on my guesses as to what the method is, and maybe I guessed wrong.

 

data intermediate;
    set have;
    prev_exdose=lag(exdose);
    prev_subj=lag(subjid);
    if (exdose^=prev_exdose and subjid=prev_subj) or subjid^=prev_subj then group+1;
run;
proc summary data=intermediate nway;
    class group;
    id exdose subjid;
    var dose_st_dt dose_en_dt;
    output out=want min(dose_st_date)= max(dose_en_dt)=;
run;
--
Paige Miller
Jack2012
Obsidian | Level 7
OK. Thank you for your reminder.

VERY MUCH appreicated. That is what I want .

Thank you very much.

Jack.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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
  • 424 views
  • 0 likes
  • 2 in conversation