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

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

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
japelin
Rhodochrosite | Level 12

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;

 

View solution in original post

1 REPLY 1
japelin
Rhodochrosite | Level 12

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;

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 752 views
  • 2 likes
  • 2 in conversation