hello community,
this is probably very simple, but how do I calculate a day based on another date minus x days.
Data have:
ID date1 days_from_date2
1 24MAR2007 296
Data want:
ID date1 days_from_date2 Date2
1 24MAR2007 296 date1 - 296
Just subtracting.
Data have;
input ID date1:date9. days_from_date2;
format date1 date9. ;
datalines;
1 24MAR2007 296
;
run;
data want;
set have;
Date2=date1-days_from_date2;
format Date2 date9.;
run;
If DATE1 is a character variable, convert it with input as follows
data want;
set have;
Date2=input(date1,date9.)-days_from_date2;
format Date2 date9.;
run;
Just subtracting.
Data have;
input ID date1:date9. days_from_date2;
format date1 date9. ;
datalines;
1 24MAR2007 296
;
run;
data want;
set have;
Date2=date1-days_from_date2;
format Date2 date9.;
run;
If DATE1 is a character variable, convert it with input as follows
data want;
set have;
Date2=input(date1,date9.)-days_from_date2;
format Date2 date9.;
run;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.