E.g.: I want the date of the first and last hospital admission for every patient in my table
patient_id
and year
, to take the sum of a cost
variable to create a new variable that represents the total cost for each patient over a given year.encounter_date
of each patient; in other words, partitioned on patient_id
. This will create two new variables, min_encounter_date
and max_encounter_date
for each patient. When we run this query, note that no records will be dropped; rather, these new variables will be have consistent values for any given patient_id
. min_encounter_date = encounter_date
OR max_encounter_date = encounter_date
!year
) when defining our partition.