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

I have a hospital discharge data with few key date information, that are data input date (the date indicates when clerical staff at hospital actually input the record in the database) and date of birth. Because, premature babies tend to have significantly longer stay at hospital, we might miss eligible cases if we select cases too soon, in contrast, we might lose time if we select cases too late. Below code, shows my attempt to assess lag time between data input date and date of birth to see how such lagtime affects number of cases available by each month. 

 

Any suggestions to solve the problem that I end up with negative "month_diff" where month of "data input date" is smaller than the month of birth date but in different years, i.e. date_input_date(20160201)- birthdate(20150712)?

 

proc import datafile="...\data100.csv"
out=have
dbms=csv replace;
getnames=yes;
run;

data temp(drop=date_input1 birth_date); 
set have;
date_input1=input(put(date_input,8.),yymmdd8.);
month_input=month(date_input1);
birth_date=input(put(patient_birth_date,8.),yymmdd8.);
month_birth=month(birth_date);
month_diff=month_input-month_birth;

date_input6=substr(left(date_input),1,6);
date_birth6=substr(left(patient_birth_date),1,6);
month_diff6=date_input6-date_birth6;
case=1;
run;

proc means data=temp maxdec=1 noprint;
class date_birth6;
var case;
output out=counts_bd(drop=_type_ _freq_) 
sum=/autoname;
proc means data=temp maxdec=1 noprint;
class date_input6;
var case;
output out=counts_prod(drop=_type_ _freq_) 
sum=/autoname;

proc means data=temp maxdec=1 noprint;
class date_birth6;
var month_diff;
output out=counts_birth6(drop=_type_ _freq_) 
sum=/autoname;
proc means data=temp maxdec=1 noprint;
class date_input6;
var month_diff6;
output out=counts_prod6(drop=_type_ _freq_) 
sum=/autoname;
run;

 Thanks for your time indeed.

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisNZ
Tourmaline | Level 20

1- Something is wrong here.

You can't use DATE_INPUT as a SAS date and as a string like you do:

DATE_INPUT1=input(put(DATE_INPUT,8.),yymmdd8.);

DATE_INPUT6=substr(left(DATE_INPUT),1,6);

2- Have you tried

MONTH_DIFF=intck('month',MONTH_BIRTH,MONTH_INPUT);

Look at the different parameters for this function.

View solution in original post

2 REPLIES 2
ChrisNZ
Tourmaline | Level 20

1- Something is wrong here.

You can't use DATE_INPUT as a SAS date and as a string like you do:

DATE_INPUT1=input(put(DATE_INPUT,8.),yymmdd8.);

DATE_INPUT6=substr(left(DATE_INPUT),1,6);

2- Have you tried

MONTH_DIFF=intck('month',MONTH_BIRTH,MONTH_INPUT);

Look at the different parameters for this function.

Cruise
Ammonite | Level 13

Just wanted to post my final program here, in case if anyone needs.

data temp; set have;
days= intck('days',input(patient_birth_date ,yymmdd8.),input(input_date,yymmdd8.));
birth_date=input(put(patient_birth_date,8.),yymmdd8.);
month_birth=month(birth_date);

pro_date=input(put(input_date,8.),yymmdd8.);
month_pro=month(pro_date);
year_pro=year(pro_date);
case=1;
run;

proc print data=temp(obs=10);
run;

proc means data=temp n mean clm median min max maxdec=0;
class birth_date;
var days;
format birth_date monname.;
run;

Thanks. 

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
  • 2 replies
  • 540 views
  • 1 like
  • 2 in conversation