BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Sammy_G
Calcite | Level 5
FILENAME REFFILE '/home/u63367626/PATIENTS/Patients.xlsx';

PROC IMPORT DATAFILE=REFFILE
DBMS=XLSX
OUT=WORK.patt;
GETNAMES=YES;
RUN;

PROC CONTENTS DATA=WORK.patt;
RUN;


data patt1;
set patt;
format dob1 date9.;

dob=compress(cat(month,'/',day,'/',year));
dob1=input(dob,mmddyy10.);

age = (dob1)/365.;

run;
1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

 

 

If your Month, Day and Year variables are numeric then use the MDY function to get a SAS date value:

 

Dob = mdy(month, day, year);

 

AGE requires a date to report the the age as of.  There is a SAS function YRDIF that takes two dates and will return years and fraction of a year as a decimal value.

 

Age_today = yrdif(dob, Today() );

Better would be to pick a date for an "age as of" such as this to calculate an age as of the first day of 2023. Any date you use with a literal value is ddMONyyyy in quotes followed by the d which tells SAS that you want the SAS date value.:

Age = yrdif(dob, '01JAN2023'd);

If you do not want the decimal portion then use the Floor function to round down to the integer.

Age_today = floor(yrdif(dob, Today() ));

 

SAS dates are the number of days since 1 Jan 1960 so dividing by 365 would give you close to the number of years since 1 Jan 1960 but only for those born after that date. Anyone born before that day would have a negative "age".

 

 

View solution in original post

2 REPLIES 2
ballardw
Super User

 

 

If your Month, Day and Year variables are numeric then use the MDY function to get a SAS date value:

 

Dob = mdy(month, day, year);

 

AGE requires a date to report the the age as of.  There is a SAS function YRDIF that takes two dates and will return years and fraction of a year as a decimal value.

 

Age_today = yrdif(dob, Today() );

Better would be to pick a date for an "age as of" such as this to calculate an age as of the first day of 2023. Any date you use with a literal value is ddMONyyyy in quotes followed by the d which tells SAS that you want the SAS date value.:

Age = yrdif(dob, '01JAN2023'd);

If you do not want the decimal portion then use the Floor function to round down to the integer.

Age_today = floor(yrdif(dob, Today() ));

 

SAS dates are the number of days since 1 Jan 1960 so dividing by 365 would give you close to the number of years since 1 Jan 1960 but only for those born after that date. Anyone born before that day would have a negative "age".

 

 

Sammy_G
Calcite | Level 5
Thank you very much, you were really helpful.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 557 views
  • 1 like
  • 2 in conversation