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^^
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.
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;
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.
Are these actually SAS dates in your data set, or are the character strings? Are the variables character or numeric?
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.
data dates;
date1='01jan2009'd;
date2='01jan2018'd;
daysbetween=date2-date1;
run;
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 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: