Help using Base SAS procedures

Calcuating age category

Reply
Frequent Contributor
Posts: 122

Calcuating age category

Hi ,

I got the below code a from a co-worker of mine and I am trying to count the male and female age categories in the below order. The problem with the below code is that if the male of female's age is greater than 18 and less than 64 or greater than 65 and above it is not counted twice.

I want to capture the count of the age of the female in the correct age category f18-44 ,f44-54, f 55-64 and f18-64 and also in f18-64.

eg: if the age of female is 55, the I want the varibales f55-64 and f18-64 to be populated as 1.

The same needs to happen for  males and the age category f65 and above & m65 and above. Please help.

Sample code:

data step5_a(drop=i);

        merge one(in=a) mbr__span(in=b);

   by member;

   if a and b;

     attrib f18_44 length=3 label='Females, Age 18 to 44'

            f45_54 length=3 label='Females, Age 45 to 54'

            f55_64 length=3 label='Females, Age 55 to 64'

            f65_74 length=3 label='Females, Age 65 to 74'

            f75_84 length=3 label='Females, Age 75 to 84'

            f85_UP length=3 label='Females, Age 85 and UP'

  f18_64 length=3 label='Females, Age 18 and 64'

  f65_UP length=3 label='Females, Age 65 and UP'

            m18_44 length=3 label='Males, Age 18 to 44'

            m45_54 length=3 label='Males, Age 45 to 54'

            m55_64 length=3 label='Males, Age 55 to 64'

            m65_74 length=3 label='Males, Age 65 to 74'

            m75_84 length=3 label='Males, Age 75 to 84'

            m85_UP length=3 label='Males, Age 85 and UP'

  m18_64 length=3 label='Males, Age 18 and 64'

  m65_UP length=3 label='Males, Age 65 and UP' ;

    array ag(*) f18_44--m65_UP;

   age=int(intck('month',&dob,&dis_dt)/12);

     if &sex not in ('F' 'M') or age lt -1 then agegp=0;

        else if age ge 18 and age le 44 then agegp=1+8*(&sex='M');

        else if age ge 45 and age le 54 then agegp=2+8*(&sex='M');

        else if age ge 55 and age le 64 then agegp=3+8*(&sex='M');

        else if age ge 65 and age le 74 then agegp=4+8*(&sex='M');

        else if age ge 75 and age le 84 then agegp=5+8*(&sex='M');

        else if age ge 85               then agegp=6+8*(&sex='M');

  else if age ge 18 and age le 64 then agegp=7+8*(&sex='M');

  else if age ge 65               then agegp=8+8*(&sex='M');

     do i=1 to dim(ag);

        if agegp=i then ag(i)=1;

        else ag(i)=0;

     end;

   

run;

Super User
Posts: 10,500

Re: Calcuating age category

These lines

else if age ge 18 and age le 64 then agegp=7+8*(&sex='M'); 

  else if age ge 65               then agegp=8+8*(&sex='M');

are basically never going to execute as the conditions are met in the previous else clauses.

In your use of these variables do you really need variables or are willing to accept a report table with appropriate headings?

Also, why macro variables SEX, dob and dis_dt? It would probably be better they were values in either dataset one or mbr__span.

Frequent Contributor
Posts: 122

Re: Calcuating age category

@ ballardw

     Right. I need those variables to do other calculation based on the age category.  SEX, Dob and Dis_dt are in the input datasets.

Ask a Question
Discussion stats
  • 2 replies
  • 290 views
  • 0 likes
  • 2 in conversation