DATA Step, Macro, Functions and more

End of Month function

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 16
Accepted Solution

End of Month function

I need to create a end of month field using a current date field.  The assignment date field has mutliple dates based on the actual assignment date.  For charting purposes i need to have only one date that corresponds to each month.  I have tried the below, however it does not populate anything.  Please help.

THE ASSIGNMENT DATA TYEP IS DATE

Data work.Data;

     set work.Data ;
     lastDay=intnx('month',AssignmentDte,0,'E');

RUN;

QUIT;


Accepted Solutions
Solution
‎03-04-2015 04:57 PM
Respected Advisor
Posts: 4,173

Re: End of Month function

Posted in reply to thomask23

or if you want to stay with datetime values:

Data work.want;

     set work.Data ;

     attrib lastDay datetime20.;
     lastDay=intnx('dtmonth',AssignmentDte,0,'E');

RUN;


For reporting purposes just use a different format for lastDay with prints the internal SAS datetime value in the way you want it to.

View solution in original post


All Replies
Contributor
Posts: 52

Re: End of Month function

Posted in reply to thomask23

Apparently your variable is a character variable. need to transform into a date variable.

Data t_a;
     lastDay1=intnx('month',today(),0,'E');
     a1 = 20000;
     lastDay2=intnx('month',a1,0,'E');
     a2 = '20140415';
     lastDay3=intnx('month',input(a2, yymmdd8.),0,'E');
     format lastday1 lastday2 lastday3 date9.;
RUN;

dataset t_a gives:
==========================================================
lastDay1      a1      lastDay2       a2        lastDay3

31MAR2015    20000    31OCT2014    20140415    30APR2014
==========================================================

Occasional Contributor
Posts: 16

Re: End of Month function

That syntax isnt working for me. Perhaps there is something going on with my data that i need to figure out.  as a workaround, Is there a way to only return the month and the year?

Super User
Posts: 19,782

Re: End of Month function

Posted in reply to thomask23

Format the variable.

Also, if you're learning to program don't make the name in the DATA statement be the same as the name in the SET statement. This will overwrite your original data set and make it hard to find/debug code.

You will need to recreate the 'data' dataset before you can go ahead.

Data Data2;

     set work.Data ;
     lastDay=intnx('month',AssignmentDte,0,'E');

     format lastDay yearmon7.;

RUN;

PROC Star
Posts: 7,471

Re: End of Month function

Posted in reply to thomask23

What does your log show when you run your original code?

Occasional Contributor
Posts: 16

Re: End of Month function


NOTE: Invalid argument to function INTNX at line 21 column 15.

ASSIGNMENTDTE=07JAN2014:00:00:00.000000

PROC Star
Posts: 7,471

Re: End of Month function

Posted in reply to thomask23

Data work.want;

     set work.Data ;
     lastDay=intnx('month',datepart(AssignmentDte),0,'E');

RUN;


Solution
‎03-04-2015 04:57 PM
Respected Advisor
Posts: 4,173

Re: End of Month function

Posted in reply to thomask23

or if you want to stay with datetime values:

Data work.want;

     set work.Data ;

     attrib lastDay datetime20.;
     lastDay=intnx('dtmonth',AssignmentDte,0,'E');

RUN;


For reporting purposes just use a different format for lastDay with prints the internal SAS datetime value in the way you want it to.

🔒 This topic is solved and locked.

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

Discussion stats
  • 7 replies
  • 5250 views
  • 0 likes
  • 5 in conversation