DATA Step, Macro, Functions and more

Referring Variable from SAS fileco

Occasional Contributor
Posts: 6

Referring Variable from SAS fileco


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:MMSmiley FrustratedS (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.

Trusted Advisor
Posts: 1,270

Re: Referring Variable from SAS fileco

Try this.

data have;

input Obs ID1 ID2 Cons_Date :anydtdtm.;


format month_end date9.;


1      1234       45678    06APR2015:00:00:00


proc print;


Super User
Posts: 23,705

Re: Referring Variable from SAS fileco

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.;


Ask a Question
Discussion stats
  • 2 replies
  • 3 in conversation