Help using Base SAS procedures

convert birthdate to age

Reply
Regular Contributor
Regular Contributor
Posts: 238

convert birthdate to age

I am trying in SAS to convert my column name BTH_DT to an age and used this code:

bth_dt = int(datediff("m",[bth_dt],date())/12)

this is contained in my proc sql statement which is

proc sql;

(select distinct

memberid,

fst_srvc_dt,

bth_dt = int(datediff("m",[bth_dt],date())/12),

member_gender_cd

from inpatient

rest of code

the entire code works great if I take out the converting to age. It will give me all columns and the bth_dt column. but when i add this code in I get an error

something expected between bth_dt and = just not sure how to code this quite right

Frequent Contributor
Frequent Contributor
Posts: 89

Re: convert birthdate to age

You might try

proc sql;

select distinct

memberid,

fst_srvc_dt,

int(datediff("m",[bth_dt],date())/12) as bth_dt,

intck("YEAR", bth_dt, date(),"CONTINUOUS") as memberAge,

member_gender_cd

from inpatient;

UPDATED with information from PGSTATS below.

Respected Advisor
Posts: 3,124

convert birthdate to age

This topic definitely belongs to FAQ, it could have so many different answers.You can find one of recent discussions from SAS-L @:

http://listserv.uga.edu/cgi-bin/wa?A2=ind1201B&L=sas-l&P=R13704#TOP

Regards,

Haikuo

Respected Advisor
Posts: 4,654

convert birthdate to age

It seems the dateDiff has been replaced with intck. You would need     intck("YEAR", bth_dt, date(),"CONTINUOUS") as memberAge in your query.

PG

PG
Regular Contributor
Regular Contributor
Posts: 238

convert birthdate to age

I get the error from intick as:               data type "year" does not match a defined type name

Regular Contributor
Regular Contributor
Posts: 238

convert birthdate to age

sorry I did put in intck not intick but still the same error applies

Respected Advisor
Posts: 4,654

convert birthdate to age

If bth_dt is a SAS DATETIME value and not a SAS DATE value then you should use "DTYEAR" as the time unit in intck and DATETIME() instead of DATE().

PG

PG
Regular Contributor
Regular Contributor
Posts: 238

convert birthdate to age

BTH_DT is not a SAS date or SAS Datetime

It is the birthdate of the member in the DB2 table. I am connecting to our DB2 server using an ODBC. The BTH_DT is a predefined column in our members table that we have insurance coverage.

Respected Advisor
Posts: 4,654

convert birthdate to age

Normally, dates are translated properly between other DBMS and SAS. When you receive a date in SAS, it is a proper SAS DATE or a proper SAS DATETIME. This is my experience but  I don't know about DB2. - PG

PG
Regular Contributor
Regular Contributor
Posts: 238

convert birthdate to age

ok. Well I did try it and still getting errors. I will see if my boss knows the answer or maybe someone on our SAS team

Regular Contributor
Regular Contributor
Posts: 238

convert birthdate to age

Just hate going those routes cuz our SAS team takes weeks to respond to anything

Respected Advisor
Posts: 4,654

convert birthdate to age

Well, give us your last try and the log, maybe only a small error left. - PG

PG
Regular Contributor
Regular Contributor
Posts: 238

convert birthdate to age


intck("dtyear", bth_dt, datetime(), "CONTINUOUS") as memberage

the error log says:

syntax error: data type "DTYEAR" does not match a defined type name

Respected Advisor
Posts: 4,654

convert birthdate to age

Strange, "DTYEAR" is an interval name, not a "defined type name". The error might have occured elsewhere in the query.

Anyhow, Time Interval functions are a bit new to SAS (I'm using version 9.3). So, you might try

intck("YEAR", datepart(bth_dt), DATE(), "C")

or maybe

dateDiff("y",datepart(bth_dt), DATE())      /* If there really is a function called dateDiff in SAS */

or else, go for the close approximation

int((datepart(bth_dt) - date())/365.25)

PG

PG
Regular Contributor
Regular Contributor
Posts: 238

convert birthdate to age

I am on 9.2 SAS

Ask a Question
Discussion stats
  • 20 replies
  • 2205 views
  • 0 likes
  • 7 in conversation