BookmarkSubscribeRSS Feed
Droopy
Calcite | Level 5
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.
4 REPLIES 4
FredrikE
Rhodochrosite | Level 12
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
DF
Fluorite | Level 6 DF
Fluorite | Level 6
Oops - double response. That's what I get for being slow, lol.
DF
Fluorite | Level 6 DF
Fluorite | Level 6
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.
Droopy
Calcite | Level 5
Thanks all. It's work !!! 😉

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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