BookmarkSubscribeRSS Feed
☑ This topic is solved. 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

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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