DATA Step, Macro, Functions and more

Referring Variable from SAS fileco

Reply
Occasional Contributor
Posts: 6

Referring Variable from SAS fileco

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: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,228

Re: Referring Variable from SAS fileco

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;

Super User
Posts: 19,768

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

run;

Ask a Question
Discussion stats
  • 2 replies
  • 189 views
  • 0 likes
  • 3 in conversation