BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
data have;
input date $ 10.;
cards;
2017-01-01
2016-10
2010-11
;
run;

Required:

2017-01-01
2016-10-31
2010-11-30
1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
data want;
set have;

if length(date)<10 then date_num =intnx('month', input(cats(date, '-01'), yymmdd10.), 0, 'e');

else date_num = input(date, yymmdd10.);
format date_num date9.;


run;

View solution in original post

7 REPLIES 7
novinosrin
Tourmaline | Level 20
data have;
input date $ 10.;
cards;
2017-01-01
2016-10
2010-11
;
run;

data want;
set have;
new_date=input(date,anydtdte21.);
if length(date)=7 then new_Date=intnx('month',new_date,0,'e');
format new_date yymmdd10.;
run;
Reeza
Super User
data want;
set have;

if length(date)<10 then date_num =intnx('month', input(cats(date, '-01'), yymmdd10.), 0, 'e');

else date_num = input(date, yymmdd10.);
format date_num date9.;


run;
rajeshalwayswel
Pyrite | Level 9

Thanks to both. but the year is leap year in this scenario what would be the solution?

novinosrin
Tourmaline | Level 20

Please test and let me know

Reeza
Super User

Leap year doesn't matter.

 


@rajeshalwayswel wrote:

Thanks to both. but the year is leap year in this scenario what would be the solution?


 

ballardw
Super User

@rajeshalwayswel wrote:

Thanks to both. but the year is leap year in this scenario what would be the solution?


SAS knows which years are leap years, at least through 19999 the last time looked, and 'e' option in intnx takes that into account.

 

Yes I said 19999. I had to demonstrate this multiple times during Y2K worries about the data I was storing in SAS. The date formats don't display properly because of the 5-digit year but the date functions work just fine.

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
  • 7 replies
  • 1065 views
  • 0 likes
  • 4 in conversation