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
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.
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
It seems the dateDiff has been replaced with intck. You would need intck("YEAR", bth_dt, date(),"CONTINUOUS") as memberAge in your query.
PG
I get the error from intick as: data type "year" does not match a defined type name
sorry I did put in intck not intick but still the same error applies
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
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.
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
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
Just hate going those routes cuz our SAS team takes weeks to respond to anything
Well, give us your last try and the log, maybe only a small error left. - PG
intck("dtyear", bth_dt, datetime(), "CONTINUOUS") as memberage
the error log says:
syntax error: data type "DTYEAR" does not match a defined type name
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
I am on 9.2 SAS
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.