BookmarkSubscribeRSS Feed
LisaSAS
Obsidian | Level 7

I am fairly new to SAS and am struggling with dates!  I need to take what's in the 'Have' column and convert it to what's in 'Beginning' and 'End'.  Here's the code I have;

t2.end_date as Have,

QTR(DATEPART(t2.end_date)) as Quarter, /*Gets me the number of the quarter (1-4)*/

INTNX('Quarter',t2.end_date,1,'B') as tmp,

 

Have     Want
  Quarter Beginning End   Beginning End
31JAN2015:00:00:00.000 1 . .   1-Jan-2015 31-Mar-2015
28FEB2015:00:00:00.000 1 . .   1-Jan-2015 31-Mar-2015
31MAR2015:00:00:00.000 1 . .   1-Jan-2015 31-Mar-2015
30APR2015:00:00:00.000 2 . .   1-Apr-2015 30-Jun-2015
31MAY2015:00:00:00.000 2 . .   1-Apr-2015 30-Jun-2015
30JUN2015:00:00:00.000 2 . .   1-Apr-2015 30-Jun-2015
31JUL2015:00:00:00.000 3 . .   1-Jul-2015 30-Sep-2015
2 REPLIES 2
DanZ
Obsidian | Level 7

This:

 

INTNX('Quarter',datepart(t2.have),1,'B') as tmp,

 

is going to shift the date to the following quarter. You need to change it to:

 

 

INTNX('Quarter',datepart(t2.have),0,'Begin') as beginning,
INTNX('Quarter',datepart(t2.have),0,'End') as end,

making sure to put the date in the have variable.

Reeza
Super User

Change your third argument to INTNX to 0

Make sure you're working with a DATE variable, datepart() function

Interval is QTR/QUARTER

 

INTNX('QTR',datepart(t2.end_date),0,'B')

SAS Innovate 2025: Call for Content

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 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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