Reputation: 1359
I'm using SAS with SQL procedures. I need to compute a field as a date difference from today, ex the number of days from the birth date.
PROC SQL;
CREATE TABLE myTable AS
SELECT BIRTH_DATE, <some function> AS DAYS_BETWEEN_BIRTHDATE_AND_TODAY
FROM someTable
What's the best way to do this and what if I want to compute monthly difference or yearly difference?
Upvotes: 0
Views: 24157
Reputation: 11556
You can use INTCK()
to get the number of days between today()
and Birth_Date
column.
Code
proc sql;
create table myTable as
select Birth_Date, intck('day', Birth_date, today()) as No_of_days
from someTable;
quit;
Upvotes: 1
Reputation: 1359
I found this function, I'm looking for other solutions.
%let today=%sysfunc(date());
PROC SQL;
CREATE TABLE myTable AS
SELECT BIRTH_DATE,
intck('DAYS', datepart(BIRTH_DATE), &today) AS DAYS_BETWEEN_BIRTHDATE_AND_TODAY
FROM someTable
Is possible to change 'DAYS' with 'MONTHS' or 'YEARS
Upvotes: 1