DATA Step, Macro, Functions and more

end of month date

Accepted Solution Solved
Reply
Contributor
Posts: 66
Accepted Solution

end of month date

Hi,

I'm not sure how to classify an ID to the month end date when I have a date variable for them.

for example i'd like my data set to look like: where i have ID and Date and need to create FILE PERIOD

ID Date FILE_PERIOD

1 01Jan2012 31Jan2012

2 05Feb2012 29Feb2012

etc..

thank you for your help.


Accepted Solutions
Solution
‎03-07-2012 01:20 PM
Respected Advisor
Posts: 3,156

Re: end of month date

Posted in reply to Danglytics

Then try this:

data want ;

set have;

_n_=intnx('month',date,0,'e');

FILE_PERIOD=cats(put(_n_, yymon7.),day(_n_));

run;

Haikuo

Edit: just updated.

View solution in original post


All Replies
Respected Advisor
Posts: 3,156

Re: end of month date

Posted in reply to Danglytics

Try this one:

data have;

input id $ date :date9.;

format date date9.;

cards;

1 01Jan2012

2 05Feb2012

;

data want;

set have;

FILE_PERIOD=intnx('month',date,0,'e');

format FILE_PERIOD date9.;

run;

Regards,

Haikuo

Contributor
Posts: 66

Re: end of month date

Great thank you  that worked.

Is there a way to get FILE_PERIOD into a character format with the following format structure?

for example the code above will give me 31Jan2012, but i'd like FILE_PERIOD to be 2012Jan31 so that it is consistent with my other formats.

Solution
‎03-07-2012 01:20 PM
Respected Advisor
Posts: 3,156

Re: end of month date

Posted in reply to Danglytics

Then try this:

data want ;

set have;

_n_=intnx('month',date,0,'e');

FILE_PERIOD=cats(put(_n_, yymon7.),day(_n_));

run;

Haikuo

Edit: just updated.

Contributor
Posts: 66

Re: end of month date

Thank you very much.

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 132 views
  • 0 likes
  • 2 in conversation