BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Ahsan
Calcite | Level 5

Hello,

 

My dba send me this SQL Query which I need to tested in SAS to validate the data

 

 

FLOOR (MONTHS_BETWEEN ( TO_DATE((case when to_char(dt.month_bgn_dt, 'MM') > '06' then TO_CHAR(to_char(dt.month_bgn_dt,'YYYY'))||'0701' else TO_NUMBER(to_char(dt.month_bgn_dt,'YYYY')-1)||'0701' end),'YYYYMMDD'),mbr.BRTH_DT )/12) mbr_age_bos

 

how do I convert this into SAS Query to calculate the age

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

OK, then the code should be like:

 

age = intck("YEAR", <mbr_brthdt>, intnx("YEAR.7", <rpt_period>, 0), "CONTINUOUS");

with, again, <mbr_brthdt> and <rpt_period> being SAS dates.

 

PG

View solution in original post

20 REPLIES 20
Ahsan
Calcite | Level 5

How do calculate the age

 

Member Age at beginning of the State Fiscal Year July 1.  Determine beginning of SFY (yyyy) from RPT_PERIOD (yyyymm). Calculate MBR_AGE_BOS at 7/1/yyyy according to MBR_BRTH_DT.

 

Please help me with this.

SASKiwi
PROC Star

Are you going to be querying SAS data or a database table and if so what database?

Ahsan
Calcite | Level 5

I will be querying database table and its an oracle database.

SASKiwi
PROC Star

OK, then why not just use an SQL passthru query and then you can use the Oracle query as it is? If you are not familiar with passthru here is an example here: http://support.sas.com/kb/19/205.html. Get your query working in Oracle first and then paste it into your PROC SQL step.

PGStats
Opal | Level 21

In SAS,

 

age = intck("YEAR", <birthdate>, <date>, "CONTINUOUS");

where <birthdate> and <date> are SAS dates.

 

PG
Ahsan
Calcite | Level 5

Hi PG,

 

here is the business logic

Member Age at beginning of the State Fiscal Year July 1.  Determine beginning of SFY (yyyy) from RPT_PERIOD (yyyymm). Calculate MBR_AGE_BOS at 7/1/yyyy according to MBR_BRTH_DT.

 

and that's the Dba code

 

FLOOR (MONTHS_BETWEEN ( TO_DATE((case when to_char(dt.month_bgn_dt, 'MM') > '06' then TO_CHAR(to_char(dt.month_bgn_dt,'YYYY'))||'0701' else TO_NUMBER(to_char(dt.month_bgn_dt,'YYYY')-1)||'0701' end),'YYYYMMDD'),mbr.BRTH_DT )/12) mbr_age_bos

I see the data in SAS which dba created and I need to validated.

Reeza
Super User

@Ahsan wrote:

Hi PG,

 

here is the business logic

Member Age at beginning of the State Fiscal Year July 1.  Determine beginning of SFY (yyyy) from RPT_PERIOD (yyyymm). Calculate MBR_AGE_BOS at 7/1/yyyy according to MBR_BRTH_DT.

 

and that's the Dba code

 

FLOOR (MONTHS_BETWEEN ( TO_DATE((case when to_char(dt.month_bgn_dt, 'MM') > '06' then TO_CHAR(to_char(dt.month_bgn_dt,'YYYY'))||'0701' else TO_NUMBER(to_char(dt.month_bgn_dt,'YYYY')-1)||'0701' end),'YYYYMMDD'),mbr.BRTH_DT )/12) mbr_age_bos

I see the data in SAS which dba created and I need to validated.


 

Are you looking to calculate the exact age as of July 1 or to replicate the logic in the code above? That's not necessarily the same thing. 

 

Here's a write up on calculating ages in SAS

https://kb.iu.edu/d/aczw

Ahsan
Calcite | Level 5
HI Reeza,

I would like to replicate the logic and calculate the age.
Reeza
Super User

It'll help if you post some sample data and expected output. 

 

I'm less inclined to do line to line/function conversion this time of night....but in general,

TO_CHAR -> PUT()

|| -> CATT()

YEAR() will take the year of a date

DATEPART() will extract the date, if it's a datetime

MDY() to calculate date

INTCK() to calculate the number of months between the intervals, also has an AGE parameter

 

Assuming you have two dates, something like the following:

 

intck('month', date_birth, mdy(7, 1, year(month_bgn_dt))) / 12 

 

 

Ahsan
Calcite | Level 5
reeza,

you have a email address I can send you the screen shots of the data
Ahsan
Calcite | Level 5

I post the screen shot I used your formula and I got the results but you will see test which I am testing. My test age should match MBR_AGE_BOS  

Ahsan
Calcite | Level 5
I would like to calculate exact age as of July 1
PGStats
Opal | Level 21

OK, then the code should be like:

 

age = intck("YEAR", <mbr_brthdt>, intnx("YEAR.7", <rpt_period>, 0), "CONTINUOUS");

with, again, <mbr_brthdt> and <rpt_period> being SAS dates.

 

PG
Ahsan
Calcite | Level 5
Thank you PG I appreciate your help

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 2299 views
  • 0 likes
  • 4 in conversation