BookmarkSubscribeRSS Feed
tmm
Fluorite | Level 6 tmm
Fluorite | Level 6

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

20 REPLIES 20
HB
Barite | Level 11 HB
Barite | Level 11

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.

Haikuo
Onyx | Level 15

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

PGStats
Opal | Level 21

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
tmm
Fluorite | Level 6 tmm
Fluorite | Level 6

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

tmm
Fluorite | Level 6 tmm
Fluorite | Level 6

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

PGStats
Opal | Level 21

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
tmm
Fluorite | Level 6 tmm
Fluorite | Level 6

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.

PGStats
Opal | Level 21

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
tmm
Fluorite | Level 6 tmm
Fluorite | Level 6

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

tmm
Fluorite | Level 6 tmm
Fluorite | Level 6

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

PGStats
Opal | Level 21

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

PG
tmm
Fluorite | Level 6 tmm
Fluorite | Level 6


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

the error log says:

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

PGStats
Opal | Level 21

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
tmm
Fluorite | Level 6 tmm
Fluorite | Level 6

I am on 9.2 SAS

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 20 replies
  • 4767 views
  • 0 likes
  • 7 in conversation