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;

 

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

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