BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
marysmith
Calcite | Level 5
data patients1; 
set patients;
format authorisation ddmmyy10.;
if NIS_Nummer in (2628,3078,6791) then authorisation='11Jan2008'd;
if NIS_Nummer in (2408) then authorisation='28Aug2007'd;
if NIS_Nummer in (6759) then authorisation='18Sep2014'd;
if NIS_Nummer in (2311,5361,6887) then authorisation="23Apr2007"d;
if NIS_Nummer in (6687) then authorisation="03Aug2009"d;
if NIS_Nummer in (6667) then authorisation="27May2015"d;
run;

data datensatz_pms; 
set datensatz_pms;
format n_date ddmmyy10.;
n_date = input(notificationdate,ddmmyy10.);
if '01jan2013'd <= n_date <= '31dec2013'd then year=2013;
if '01jan2014'd <= n_date <= '31dec2014'd then year=2014;
if '01jan2015'd <= n_date <= '31dec2015'd then year=2015;
if '01jan2016'd <= n_date <= '31dec2016'd then year=2016;
if '01jan2017'd <= n_date <= '31dec2017'd then year=2017;
run;                                                    

Dear community,

 

thank you for your instant support when i am struggeling with sas.

I need your help again.

Now I have to measure the difference between two date Variables (notification date and authorisation date) and if the time difference between the authorisation date and the notification date is shorter than 2 years I its a newly authorised drug and if the time difference is longer than 2 years its not a newly authorised drug. I need Sas to create me a new variable with that information(newly authorised: yeys/no). But how to create this variable?

 

I really need your support with this as I have absolutely no idea^^

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

No. If you have two date variables, lets say date1 and date2 in a data set like this

 

data dates;
date1='01jan2009'd;
date2='01jan2018'd;
format date: date9.;
run;

and you want to calculate the difference between them, measured in years, do like this

 

data want;
   set dates;
   yearsbetween=intck('year',date1,date2);
run;

Change the first argument in the INTCK Function to day, week, month or whatever interval you want to measure.

View solution in original post

9 REPLIES 9
PeterClemmensen
Tourmaline | Level 20

Subtract the two dates from each other or use the INTCK Function to measure how many specified intervals there are between two dates like this

 

data test;
days=intck('day','01jan2009'd,'01jan2018'd);
weeks=intck('week','01jan2009'd,'01jan2018'd);
months=intck('month','01jan2009'd,'01jan2018'd);
years=intck('year','01jan2009'd,'01jan2018'd);
run;

 

marysmith
Calcite | Level 5
How do I use it with those two variables?
Like this?
data patients_new;
set patients
days=intck('authorisationdate', '01aug2011'd,'notificationdate' '01feb2012'd);
put days=;
run;


PeterClemmensen
Tourmaline | Level 20

No. If you have two date variables, lets say date1 and date2 in a data set like this

 

data dates;
date1='01jan2009'd;
date2='01jan2018'd;
format date: date9.;
run;

and you want to calculate the difference between them, measured in years, do like this

 

data want;
   set dates;
   yearsbetween=intck('year',date1,date2);
run;

Change the first argument in the INTCK Function to day, week, month or whatever interval you want to measure.

marysmith
Calcite | Level 5
Ok thanks! But I already have the 2 variables with the dates for all 260 cases. My dataset looks like that. And now I need sas to substrate those two dates for all 260 cases and create me a new variable (new_authorised:0/1)
Number authorization notificationdate new_auth
1 12/02/2008 10/05/2014 0
2 15/06/2004 02/02/2015 0
3 07/08/2013 21/10/2014 1


PaigeMiller
Diamond | Level 26

Are these actually SAS dates in your data set, or are the character strings? Are the variables character or numeric?

--
Paige Miller
PaigeMiller
Diamond | Level 26

You subtract one date from the other. This assumes your variables are SAS date values. Then you can see if that value is >730 (which is two years in days).

 

If you need more details, you have to provide more details, and show us a small portion of the relevant data.

--
Paige Miller
marysmith
Calcite | Level 5
Thank you!
But how to substract those two variables? What information do you need?
PeterClemmensen
Tourmaline | Level 20
data dates;
date1='01jan2009'd;
date2='01jan2018'd;
daysbetween=date2-date1;
run;
marysmith
Calcite | Level 5
Oh yeah that was easy^^ thank you 🙂

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
  • 9 replies
  • 2052 views
  • 0 likes
  • 3 in conversation