BookmarkSubscribeRSS Feed
imdickson
Quartz | Level 8

Hi SAS Expertise,

 

I am trying this code:

%put %sysfunc(intnx(year,%sysfunc(today()),1),date9.);

 

Based on the online guide from google, it should return the date 13th Jun 2018 as i want to get 1 year increment from today.

However, I am only getting 1st Jan 2018. May i know which part is wrong/missing from the code above?

5 REPLIES 5
PeterClemmensen
Tourmaline | Level 20

Use 'sameday' as the alignment option

 

data _null_;
	format var date9.;
	var = intnx('year',today(),1,'sameday');
	put var;
run;

 Consulting the documentation, the default value of the alignment option is ''beginning". Allowed values are BEGINNING, MIDDLE, END, and SAMEDAY.

 

http://support.sas.com/documentation/cdl/en/etsug/63939/HTML/default/viewer.htm#etsug_tsdata_sect038...

 

 

Kurt_Bremser
Super User

Depending on the further use of the value, I'd even do

%let nextdate=%sysfunc(intnx(year,%sysfunc(today()),1,s),best.);

which allows the direct use of &nextdate in any date operation/comparison (no quotes and trailing d needed).

imdickson
Quartz | Level 8
Hi, i tried 's' but i got error until i saw your reply without the single quotation, it works! However, when i put it in SAS DI Studio, i got this error :
data null;
27 /* set ODMSCDS.FIELD;*/
28 where '2017-01-01 00:00:00'dt >= %sysfunc(intnx(year,%sysfunc(today()),-2,s),date9.);
NOTE: Line generated by the macro function "SYSFUNC".
28 13JUN2015
_______
22
76
ERROR: Syntax error while parsing WHERE clause.
ERROR: No input data sets available for WHERE statement.
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, *, **, +, -, /, <, <=, <>, =, >, >=, AND, EQ, GE, GT, LE, LT,
NE, OR, ^=, |, ||, ~=.

ERROR 76-322: Syntax error, statement will be ignored.

29 run;
PeterClemmensen
Tourmaline | Level 20

I think you have commented out your set statement as

 

/* set ODMSCDS.FIELD;*/

and you are trying to compare datetime values with dates, which will fail.

 

And just to avoid confusion when reading code, do not name a SAS dataset null 🙂

Kurt_Bremser
Super User

@imdickson wrote:
Hi, i tried 's' but i got error until i saw your reply without the single quotation, it works! However, when i put it in SAS DI Studio, i got this error :
data null;
27 /* set ODMSCDS.FIELD;*/
28 where '2017-01-01 00:00:00'dt >= %sysfunc(intnx(year,%sysfunc(today()),-2,s),date9.);
NOTE: Line generated by the macro function "SYSFUNC".
28 13JUN2015
_______
22
76
ERROR: Syntax error while parsing WHERE clause.
ERROR: No input data sets available for WHERE statement.
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, *, **, +, -, /, <, <=, <>, =, >, >=, AND, EQ, GE, GT, LE, LT,
NE, OR, ^=, |, ||, ~=.

ERROR 76-322: Syntax error, statement will be ignored.

29 run;

That's why I gave you the hint with using the best. format to obtain the raw date value, which can easily be used in such situations;

but you have an apple/orange problem, because you compare a datetime literal with a date value, which will surely fail. And the datetime literal was not correctly written (datetime literals also use the SAS date. format)!

Use

where '01jan2017'd >= %sysfunc(intnx(year,%sysfunc(today()),-2,s),best.);

instead.

 

PS after rethinking it, I'm wondering what you try to accomplish. Depending on today's date, you'd either get all observations from the dataset or none, as you are in fact comparing two literals.

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
  • 5 replies
  • 1937 views
  • 2 likes
  • 3 in conversation