BookmarkSubscribeRSS Feed
asandri
Calcite | Level 5

In my dataset, I have date of birth (dob), start date (sdate) and end/stop date (edate) and I would like to calculate age-specific person years. Ideally, a list of variables should be created that looks like this:

patientid agegrp1_24 agegrp20_25 agegrp26_35 agegrp36_

100         3.4               5                    1.2                 0

101          0                 5                     10                  3.7

etc

 

Could you please help me? Thank you.       

7 REPLIES 7
PaigeMiller
Diamond | Level 26

You will need to explain further. When you say:

 

In my dataset, I have date of birth (dob), start date (sdate) and end/stop date (edate)

 

This doesn't correspond to the table you have shown in any way. What is the connection? Explain (in words) how the desired calculations would be done. Show us a portion of this data set.

 

 

--
Paige Miller
asandri
Calcite | Level 5

Let me explain a bit further with a simple example. Let's consider a participant (partA) who was born in 1980, entered the study in 2000 and stopped participating in it in 2020 (e.g. dob=1.1.1980 sdate=1.1.2000 edate=1.1.2020). This person contributed a total of 20 person years in the study (i.e. edateb - sdate).

For my analysis, let's also say that I am organising the participants (according to their age) into 3 age groups, i.e. agegroup1: <25; agegroup2: [25-34); and agegroup3: >=35.

The 20 years of total person time partA contributed to the study are distributed across these 3 age groups, i.e. 5 years in agegroup1, 10 years in agegroup2 and 5 years in agegroup3 (since during the 20 years of their participation partA 'moved' from agegroup1 to agegroup2 and to agegroup3).

 

I hope this is clearer now, thanks in advance!

 

 

PaigeMiller
Diamond | Level 26

Repeating: "Show us a portion of this data set."

 

Also, your output table contains these headings: agegrp1_24 agegrp20_25

 

The age group 1–24 overlaps the age group 20–25. Is that really what you want? How can patient ID 100 have a 3.4 in age group 1–24 and a 5 in age group 20–25, which seems to me to be impossible and confusing.

 

Is the desired output that you show going to be used as a SAS data set for further analysis? Or is it a table for some report?

--
Paige Miller
asandri
Calcite | Level 5

Please see attached; I would like the 'py' (i.e. the total person time a person is contributing) to be distributed across the four agegrp variables/column.

Thanks again.

PaigeMiller
Diamond | Level 26

Ok, my mistake, I forgot to ask for data in a form we can use (a .pdf is not a form we can use). We need a portion of your data presented as SAS data step code (instructions). File attachments are not acceptable, as I will not download them.

 

I would also point out that I asked the following question:

 

Also, your output table contains these headings: agegrp1_24 agegrp20_25

 

The age group 1–24 overlaps the age group 20–25. Is that really what you want? How can patient ID 100 have a 3.4 in age group 1–24 and a 5 in age group 20–25, which seems to me to be impossible and confusing.

 

which you did not answer. Please, from now on, provide all the information requested.

 

--
Paige Miller
asandri
Calcite | Level 5

For the data, you can run in SAS:

 

data py1;
input dob :ddmmyy10. sdate :ddmmyy10. edate :ddmmyy10. id ageatstart ageatend py ;
format dob ddmmyy10. sdate ddmmyy10. edate ddmmyy10.;
datalines;
05/03/1980 01/01/2005 31/12/2014 1 24 34 10.0
12/08/2006 12/08/2006 31/12/2014 2 0 8 8.39
19/09/1975 01/01/2005 20/12/2011 3 29 35 6.38
;
run;

 The confusion re. age groups was due to me giving examples where different cutoff thresholds were used for organising the age group. Obviously, age groups will be organised as consecutive groups (without any overlap); so let's agree that the desired arrangement for age groups should be: agegrp1: <20; agegrp2: [20-29]; agegrp3: [30,39]; and agegrp4: >=40.

asandri
Calcite | Level 5
I forgot to mention that it will be used as data for analysis.

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