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.
Have you explored the INTNX function yet? There are lots of examples in the online help that look like what your are attempting.
Have you explored the INTNX function yet? There are lots of examples in the online help that look like what your are attempting.
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:
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.
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: