DATA Step, Macro, Functions and more

compute age from 5 dates

Frequent Contributor
Posts: 94

compute age from 5 dates

[ Edited ]

Hi All,


Need a help in this program.Little complicated. I have 5 dates (Byear1,byear2...-5), I am trying to get a new calculated column (youngest) where I need only the age of the least birthyear (2017-1958). Some birthyear variables are blank.

How to identify the least year from the 5 dates? 


proc sql;
create table test.age
as select  (2017-(birtyear1)) as Age1,

                 (2017-(byear2)) as Age2,

                 (2017-(byear3)) as Age3,

                 (2017-(byear4)) as Age4,

                  (2017-(byear5)) as Age5,




Output should be like this!

Byear1  Byear2   Byear3  Byear4   Byear5    Age1   Age2  CalculatedCol(youngest)   

1955       1958         0          0             0             62                                59                                

 1962      1965        0          1964        0             55                                52                                  

1979      1978        0            0           1962         38                                38                                   

Posts: 8,164

Re: compute age from 5 dates

Posted in reply to Kalai2008

You will get more (or maybe at least some) responses if you provide example have and want datasets in the form of data steps we can run. Your examples use different variable names and one can't really see what you are trying to do.


Art, CEO,


Super User
Posts: 23,700

Re: compute age from 5 dates

Posted in reply to Kalai2008

MIN (of birthyear1-birthyear5) will provide the lowest value, ignoring missing values.


I would recommend you check what the standard is in your industry. 

Apparently demographics uses Age as of June1st for particular years, so if you're merging it with other sources that's a good indicator. 

When I did cancer research we had a different definition, so it can be industry/topic specific.

Ask a Question
Discussion stats
  • 2 replies
  • 1 like
  • 3 in conversation