BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
NewUsrStat
Lapis Lazuli | Level 10

Hi guys, I have a date like this: 01JUL2021. How can I get 01JUL2020? I need to subtract exactly one year.

 

I tried the following but without success. The date is no more "01JUL"

my_new_date = INTNX('YEAR',mydate,-1);

 

Thank you in advance

 

 

Best

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

Hi @NewUsrStat,

 

Use 's' (the "SAME alignment") in the fourth argument of the INTNX function:

my_new_date = INTNX('YEAR',mydate,-1,'s');

The default is 'b' (beginning).

View solution in original post

3 REPLIES 3
FreelanceReinh
Jade | Level 19

Hi @NewUsrStat,

 

Use 's' (the "SAME alignment") in the fourth argument of the INTNX function:

my_new_date = INTNX('YEAR',mydate,-1,'s');

The default is 'b' (beginning).

PaigeMiller
Diamond | Level 26

@NewUsrStat wrote:

Hi guys, I have a date like this: 01JUL2021. How can I get 01JUL2020? I need to subtract exactly one year.

 

I tried the following but without success. The date is no more "01JUL"

my_new_date = INTNX('YEAR',mydate,-1);

 

So just to be 100% complete, when a date is 01JUL2021 in a numeric variable, then @FreelanceReinh has the solution. But if the date of 01JUL2021 is in a character variable (is it? you don't tell us) then that won't work. Then you want this:

 

one_year_ago = intnx('year',input(char_date_variable_name,date9.),-1,'s');

 

--
Paige Miller

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 1468 views
  • 1 like
  • 4 in conversation