How to use Age with Start Year/Month

Reply
Contributor
Posts: 49

How to use Age with Start Year/Month

Hello, I tried different ways on this basic SAS question but so far nothing worked for me. In my dataset I'm going to have all people between age 20-29 as of May 1st but if the person's age is 30 on June 1st also it should be included in my report. This is part of my logic that I used: ---where start_year = 01JAN2012 and 20 <= AGE <= 29

The above logic would not include if person’s age is 30 on June and even if I use this way: ---where start_year = 01JAN2012 and 20 <= AGE <= 30

it would include all people between age 20 – 30.

Thanks and any help is appreciated.

Super Contributor
Posts: 1,636

Re: How to use Age with Start Year/Month

did you calculate age or age was given?

Contributor
Posts: 49

Re: How to use Age with Start Year/Month

Thank you Linlin. age is given

Super Contributor
Posts: 578

Re: How to use Age with Start Year/Month

You want to include anyone who is between 20 and 29 on May1...but also those that are 30 on June 1.

-Do you want to include those who are 30 on June 1 even if they are not between 20 and 29 on May 1?

-Do you have date of birth available?

If you don't have date of birth, I'm not sure how you would ever calculate age at a certain date.

Contributor
Posts: 49

Re: How to use Age with Start Year/Month

Thanks DBailey.

You want to include anyone who is between 20 and 29 on May1...but also those that are 30 on June 1. Yes I want to include anyone between ages 20 and 30 but also anyone within the same people who reached/hit 30 on June 1st.

-Do you want to include those who are 30 on June 1 even if they are not between 20 and 29 on May 1? if the person's age was 29 on May and converted to 30 on June 1st then it should be included in my report. For example, if Mr. John's age was 29 on May and June 1st becomes 30 I want to include that in the report. As you can see I am using start_year = 01JAN2012

-Do you have date of birth available? Yes DOB is available

If you don't have date of birth, I'm not sure how you would ever calculate age at a certain date. DOB is given

I don't have a problem from ages between 20-29 but my main issue is to include my report same person who was 29 on and then hit 30 on June 1st.

Contributor
Posts: 49

Re: How to use Age with Start Year/Month

I Just want to rephrase my last respond.

You want to include anyone who is between 20 and 29 on May1...but also those that are 30 on June 1. Yes I want to include anyone between ages 20 and 29 but also anyone within the same people who reached/hit 30 on June 1st.

Super Contributor
Posts: 1,636

Re: How to use Age with Start Year/Month

example:

/*  calculate age */

data have;

input id dob mmddyy10.;

format dob mmddyy10.;

cards;

1 10/10/2000

2 1/28/1990

4/18/1964

;

data want;

  set have;

age_may=int((mdy(5,1,2013)-dob)/365.25);

age_jun=int((mdy(6,1,2013)-dob)/365.25);

if age_may>=20 and (age_may<=29 or age_jun<=30);

run;

proc print;run;

Contributor
Posts: 49

Re: How to use Age with Start Year/Month

Thanks Linlin for your try. Here is the data I've.

ID_NUM

AGE

START_YEAR

123

20

1/27/2012

123

20

5/20/2012

1234

29

5/22/2012

1234

29

6/1/2012

12345

29

5/22/2012

12345

30

6/1/2012


Super Contributor
Posts: 1,636

Re: How to use Age with Start Year/Month

You have to have date of birth in order to calculate age at different time.

Contributor
Posts: 49

Re: How to use Age with Start Year/Month

Again thanks Linlin. Here is the revised data with DOB included.

ID_NUM

AGE

START_ServYEAR

DOB

123

20

1/27/2012

1/1/1993

123

20

5/20/2012

1/1/1993

1234

29

5/22/2012

2/14/1984

1234

29

6/1/2012

2/14/1984

12345

29

5/22/2012

5/1/1984

12345

30

6/1/2012

5/1/1984


Contributor
Posts: 49

Re: How to use Age with Start Year/Month

Thanks Linlin for your help. RichardinOz thanks as well for your input but I have to calcuate DOB as Linlin indicated. Linlin respond worked for me with some editions I made to my original data. Have a great evening everyone

Super Contributor
Posts: 644

Re: How to use Age with Start Year/Month

Your requirement seems to translate to the conditions

where DOB > '01MAY1983'D and DOB <= '01MAY1993'D

if my mental arithmetic is correct

Richard

Message was edited by: Richard Carson Did some date arithmetic to update the figures

Ask a Question
Discussion stats
  • 11 replies
  • 384 views
  • 0 likes
  • 4 in conversation