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;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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