BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
thomask23
Fluorite | Level 6

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;

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

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

7 REPLIES 7
billfish
Quartz | Level 8

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
==========================================================

thomask23
Fluorite | Level 6

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?

Reeza
Super User

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;

art297
Opal | Level 21

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

thomask23
Fluorite | Level 6


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

ASSIGNMENTDTE=07JAN2014:00:00:00.000000

art297
Opal | Level 21

Data work.want;

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

RUN;


Patrick
Opal | Level 21

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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 7 replies
  • 79421 views
  • 1 like
  • 5 in conversation