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 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 8 replies
  • 1490 views
  • 8 likes
  • 5 in conversation