BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
GreggB
Pyrite | Level 9

I want to find all students in my data set who will turn 6 between 07/01/2011 and 09/01/2012.   Suggestions?   here's what the data looks like:

StudentIDStudentNameGradeSexLEPBirthDateAge
10007Smith, JohnPKMale905/24/20074
730010000865Jones, Lucy08Male906/10/199714
730010010121Miller, Sam03Male909/11/20028
10236Smith, Anna01Female909/20/20046
10538Garcia, FredPKMale107/22/20074
1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

Gregg,

I think that you may not have specified your dates correctly but, if you did, I think that the following code would do something quite close to what you want:

%let predate=30JUN2011;

%let enddate=01SEP2012;

data want;

  set have;

  age_at_predate = floor

   ((intck('month',birthdate,"&predate"d)

   - (day("&predate"d) < day(birthdate))) / 12);

  if age_at_predate in (4,5) then do;

    age_at_enddate = floor

    ((intck('month',birthdate,"&enddate"d)

    - (day("&enddate"d) < day(birthdate))) / 12);

    if age_at_enddate ge 6 then party="yes";

  end;

run;

View solution in original post

3 REPLIES 3
art297
Opal | Level 21

Gregg,

I think that you may not have specified your dates correctly but, if you did, I think that the following code would do something quite close to what you want:

%let predate=30JUN2011;

%let enddate=01SEP2012;

data want;

  set have;

  age_at_predate = floor

   ((intck('month',birthdate,"&predate"d)

   - (day("&predate"d) < day(birthdate))) / 12);

  if age_at_predate in (4,5) then do;

    age_at_enddate = floor

    ((intck('month',birthdate,"&enddate"d)

    - (day("&enddate"d) < day(birthdate))) / 12);

    if age_at_enddate ge 6 then party="yes";

  end;

run;

GreggB
Pyrite | Level 9

thanks for your help.

ArtC
Rhodochrosite | Level 12

There are a number of ways of calculating age http://www.wuss.org/proceedings10/coders/2943_4_COD-Carpenter.pdf , however for this problem a simplier solution is available.  Try the INTNX function with the 'SAME' option as the fourth argument to advance the date of birth 6 years.

data students;

input StudentID $    BirthDate :mmddyy10.;

dob6 = intnx('year',birthdate,6,'s');

if '01jul2011'd le dob6 le '01sep2012'd then note='In Range';

format birthdate dob6 date9.;

datalines;

10007        05/24/2007   

73001     06/10/1997   

73002     09/11/2002   

10236        09/20/2004   

10538        07/22/2004   

10538        07/22/2005   

10538        07/22/2006   

10538        07/22/2007   

run;

proc print data=students;

run;

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 3 replies
  • 760 views
  • 1 like
  • 3 in conversation