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: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 7013 views
  • 0 likes
  • 3 in conversation