BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sasphd
Lapis Lazuli | Level 10

hello, 

I have date format yymmn6. I want to change it to MMDDYY10.

 by adding the last day of the month 

have : 198605 

want 05/31/1986

 

thanks

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

@dexcort2020 wrote:

If it is already a date, then this does it:

2022 var mmddyy10.;
var = intnx('month',var,0,'e');

If it is a string, do this:

numdate = intnx('month',input(chardate,yymmn6.),0,'e');
2022 numdate mmddyy10.;

2022 is not a valid SAS statement.

View solution in original post

8 REPLIES 8
Kurt_Bremser
Super User

Is the variable in question already a SAS date with a format of YYMMN6., or is it a character variable containing the string?

If it is already a date, then this does it:

format var mmddyy10.;
var = intnx('month',var,0,'e');

If it is a string, do this:

numdate = intnx('month',input(chardate,yymmn6.),0,'e');
format numdate mmddyy10.;
dexcort2020
Obsidian | Level 7

If it is already a date, then this does it:

2022 var mmddyy10.;
var = intnx('month',var,0,'e');

If it is a string, do this:

numdate = intnx('month',input(chardate,yymmn6.),0,'e');
2022 numdate mmddyy10.;
Kurt_Bremser
Super User

@dexcort2020 wrote:

If it is already a date, then this does it:

2022 var mmddyy10.;
var = intnx('month',var,0,'e');

If it is a string, do this:

numdate = intnx('month',input(chardate,yymmn6.),0,'e');
2022 numdate mmddyy10.;

2022 is not a valid SAS statement.

Tom
Super User Tom
Super User

And if the original variable is numeric with values like 202,201 which humans might see as meaning January 2022 then you need add another layer to the function call sandwich.

So pick the proper second statement based on whether VAR is

1) date valued numeric

2) character

3) regular integer valued numeric.

format want mmddyy10.;
want = intnx('month',var,0,'e');
want = intnx('month',input(var,yymmn6.),0,'e');
want = intnx('month',input(put(var,z6.),yymmn6.),0,'e');
sasphd
Lapis Lazuli | Level 10

hello, 

I have date format yymmn6. I want to change it to MMDDYY10.

 by adding the last day of the month 

have : 198605 

want 05/31/1986

 

thanks

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 8 replies
  • 946 views
  • 8 likes
  • 5 in conversation