Desktop productivity for business analysts and programmers

Find the last day of the month

Reply
New Contributor
Posts: 2

Find the last day of the month

I want to find, in entreprise guide, the last day of the month. I only have a string who represent the month and the year (e.q : "200908") I want to compute a real date ==> "08/31/2009". Is anyone can help me.

Best regards.
Frequent Contributor
Posts: 120

Re: Find the last day of the month

try this sample program:

data _null_;
a = '200901';
b = intnx('month',input(a,yymmn6.),0,'end');
put b yymmdd10.;
run;

In EG use the expression (intnx('month',input(a,yymmn6.),0,'end')) to create a new variable.

//Fredrik
Frequent Contributor
Frequent Contributor
Posts: 94

Re: Find the last day of the month

Oops - double response. That's what I get for being slow, lol.
Frequent Contributor
Frequent Contributor
Posts: 94

Re: Find the last day of the month

Hi Droopy,

To do this, I would convert your text string to a normal date, then make use of the INTNX function to go forward a month, then back a day.

For example, 200908 would be converted to 08/01/2009 (sticking with US style dates). Jump forward a month to 09/01/2009, then go back a day to 08/31/2009.

The below code create a sample dataset with months stored as text, and then does the above calculation.

data months;
format month $10.;
input month $;
datalines;
200002
200908
200402
;
run;

data months;
set months;
format last_day date9.;
last_day = intnx('day',intnx('month',input(month,yymmn6.),1),-1);
run;


The Input function converts the text date to its numerical equivalent, then intnx is used as above.

Hope that helps.
New Contributor
Posts: 2

Re: Find the last day of the month

Thanks all. It's work !!! ;-)
Ask a Question
Discussion stats
  • 4 replies
  • 2232 views
  • 0 likes
  • 3 in conversation