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

Hi Everyone,

 

i am trying to use a variable from a data sent in an INTNX statement to create a new variable in the same dataset.  I would like to use the variable 'XXX' to replace the '-12' in the intnx statement below.   XXX is a numeric and represents a number of months, i.e 12 months, 18 months, 255 months, etc.  My goal is to create a new date variable, which = 'date' - XXX months.

 

As ever, thanks in advnce to all, 

 

best regards,

 

paul

 

proc sql;
create table test2 as
select extdate,
          Date,
          intnx('Month',date,-12,'s') format=date9. as new_var
from test;
quit;

 

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

You did fine.  That was my mistake.  Replace -12 with:

 

-1 * xxx

View solution in original post

4 REPLIES 4
Astounding
PROC Star

It depends on whether XXX takes on only positive values, and whether you want to move back or move forward.  At any rate, this should probably be the replacement for DATE:

 

-1*xxx

 

But if that moves you in the wrong direction, use xxx instead.

pandhandj
Obsidian | Level 7

Hi Astounding, thanks for getting backto me.

 

I dont think I have explained myself well...

 

'Date' is the date i wish to count back in time from.

'XXX'  is a variable - the number of months i want to count back from 'Date'

 

How do i get the variable 'XXX' to replace the '-12' in this - intnx('Month',date,-12,'s') format=date9. as test

 

does that make sense? 

Astounding
PROC Star

You did fine.  That was my mistake.  Replace -12 with:

 

-1 * xxx

pandhandj
Obsidian | Level 7

thanks Astounding, i appreciate your help.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 1369 views
  • 0 likes
  • 2 in conversation