BookmarkSubscribeRSS Feed
AliMN
Calcite | Level 5

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.

11 REPLIES 11
Linlin
Lapis Lazuli | Level 10

did you calculate age or age was given?

AliMN
Calcite | Level 5

Thank you Linlin. age is given

DBailey
Lapis Lazuli | Level 10

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.

AliMN
Calcite | Level 5

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.

AliMN
Calcite | Level 5

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.

Linlin
Lapis Lazuli | Level 10

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;

AliMN
Calcite | Level 5

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


Linlin
Lapis Lazuli | Level 10

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

AliMN
Calcite | Level 5

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


AliMN
Calcite | Level 5

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

RichardinOz
Quartz | Level 8

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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 11 replies
  • 1055 views
  • 0 likes
  • 4 in conversation