Hello New SAS User community, I am working in a long data set with several hundred people where every participant (var id) was prescribed an antibiotic for 10 days with each line representing 1 day (var day). The dose (var dose) may change by day. I am trying to create a variable that captures the maximum duration of each dosing change As you can see in the table below, id #1 had 4 changes over time (600mg for 4 days, 0mg for 1 day, 300mg for 3 days, and then 600mg for 2 days) and id #2 had no changes. Using the data step, created a variable 'count_state' that enumerates the number of days at each dose over time, restarting when there is a change. Help: I would like to create a new variable (bold column below) that is the maximum of count_state for each dose before there is any change. Thank you very much in advance! id day dose count_state max_count_state 1 1 600 1 4 1 2 600 2 4 1 3 600 3 4 1 4 600 4 4 1 5 0 1 1 1 6 300 1 3 1 7 300 2 3 1 8 300 3 3 1 9 600 1 2 1 10 600 2 2 2 1 600 1 10 2 2 600 2 10 2 3 600 3 10 2 4 600 4 10 2 5 600 5 10 2 6 600 6 10 2 7 600 7 10 2 8 600 8 10 2 9 600 9 10 2 10 600 10 10
... View more