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

Hi,

If I have a set date, and want to create date variables that are, 1 month, 2 month 6 month before that set date, is there a function that will be able to get me that?

for example:

set_date = 12DEC11

i want to create a new var with date 1 month before the set_date:

set_date_last_1mth = 12NOV11 ;

2 months:

set_date_last_2mth = 12OCT11 ;

is there a simple way to do this?

currently I use set_date_last_1mth = set_date - 30 ; -60 -120 etc. which isnt entirely accurate or the best way to do this.

Thanks for your help.

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Have you explored the INTNX function yet? There are lots of examples in the online help that look like what your are attempting.

View solution in original post

3 REPLIES 3
ballardw
Super User

Have you explored the INTNX function yet? There are lots of examples in the online help that look like what your are attempting.

EronitaScott
Calcite | Level 5

Hi, 

 

These are the functions used to process date and time values.

 

For Example: 

 

data date_functions;
INPUT @1 date1 date9. @11 date2 date9.;
format date1 date9. date2 date9.;

/* Get the interval between the dates in years*/
Years_ = INTCK(‘YEAR’,date1,date2);

/* Get the interval between the dates in months*/

 

List of SAS Exam and its online practice exams

SAS Certified Base Programmer for SAS 9

SAS Certified Advanced Programmer for SAS 9

SAS Certified Clinical Trials Programmer Using SAS 9

SAS Certified Clinical Trials Programmer Using SAS 9 - Accelerated Version

SAS Certified Statistical Business Analyst Using SAS 9

SAS Certified BI Content Developer for SAS 9

SAS Certified Data Integration Developer for SAS 9

SAS Certified Platform Administrator for SAS 9

SAS Big Data Preparation, Statistics, and Visual Exploration Using SAS 9

SAS Big Data Programming and Loading Using SAS 9

SAS Advanced Predictive Modeling Using SAS 9

SAS Text Analytics, Time Series, Experimentation and Optimization using SAS 9

A00-255: SAS Predictive Modeling Using SAS Enterprise Miner 14

A00-277: SAS Visual Analytics Exploration and Design

A00-262: SAS Certified Data Quality Steward for SAS 9

A00-272: SAS Certified Visual Modeler Using SAS Visual Statistics 7.4


months_ = INTCK(‘MONTH’,date1,date2);

/* Get the week day from the date*/
weekday_ = WEEKDAY(date1);

/* Get Today’s date in SAS date format */
today_ = TODAY();

/* Get current time in SAS time format */
time_ = time();
DATALINES;
21OCT2000 16AUG1998
01MAR2009 11JUL2012
;
proc print data = date_functions noobs;
run;

 

Output:

date_time_funcs_result.jpg

SAS_007
Calcite | Level 5

Hello,

 

Please use beow code to resolve your query in most efficient way:

 

data out1;

set_date = '12dec2011'd;

set_date_last_1mth = intnx('month',set_date,-1,'s');

set_date_last_2mth = intnx('month',set_date,-2,'s');

format set_date set_date_last_1mth set_date_last_2mth ddmmyy10.;

run;

 

I hope it helps. Thanks.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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