BookmarkSubscribeRSS Feed
Sreeni
Calcite | Level 5

Hi,

I have an Input file which is a SAS Data file (Data is in SAS format).

File variables and date as follows :

Obs    ID1        ID2      Cons_Date  

1      1234       45678    06APR2015:00:00:00  

It has a date filed (field name as cons_date) in format DDMMMYYYY:HH:MM:SS (Eg .. 06Apr2015:00:00:00).

I need to find out Month end date from the above field.

Eg .. here the result should come as 30Apr2015.

I need assistance in how to refer the variable (cons_date) from SAS Input file.

This could be a simple question but since I am new to SAS I require assistance for this. Can some one pls assist.

Thank you.

2 REPLIES 2
stat_sas
Ammonite | Level 13

Try this.

data have;

input Obs ID1 ID2 Cons_Date :anydtdtm.;

month_end=intnx('month',datepart(Cons_Date),0,'end');

format month_end date9.;

datalines;

1      1234       45678    06APR2015:00:00:00

;


proc print;

run;

Reeza
Super User

This assumes that the variable is numeric with a datetime format applied. If the date is character this answer does not apply.

Use the INTNX() function with a 0 increment and align the date to the end of the month using 'e'.

The DATEPART() function converts the datetime variable to a date variable.

SAS(R) 9.3 Functions and CALL Routines: Reference

data want;

set have;

date_want=intnx('month', datepart(cons_date), 0, 'e');

format date_want date9.;

run;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1084 views
  • 0 likes
  • 3 in conversation