BookmarkSubscribeRSS Feed
deleted_user
Not applicable
My code:

data dates;
start='20040228'
tmpstart=input(start,yymmdd8.)+364;
end=put(tmpstart,yymmddn8.);
run;

Result: end='20050226'. That's what I want, since the start was the next to last day in february.

start='20040229' gives end='20050227'. OK!
start='20040301' gives end='20050228'. OK!

But: start='20030301' gives end ='20040228'. I want end='20040229'.

Is there some time function that gives start + one calendar year - 1 day?
2 REPLIES 2
Oleg_L
Obsidian | Level 7
Hi
Use INTNX:

[pre]
data _null_;
start='20030301';
end=put(intnx('year',input(start,yymmdd8.),+1,'sameday')-1,yymmddn8.);
put start= end=;
run;
[/pre]
darrylovia
Quartz | Level 8
I would suggest one of the Date Time Functions in SAS such as INTNX.

Google: SAS Date Functions
http://support.sas.com/documentation/cdl/en/lrdict/63026/HTML/default/viewer.htm#a000245860.htm



Below is an example;

data dates;
length start $8;
input start $;
datalines;
20040228
20040229
20040301
20030301
;
run;

data one;
set dates;

tmpstart=input(start,yymmdd8.)+364;
end=put(tmpstart,yymmddn8.);

new_end=intnx('year',input(start,yymmdd8.),1,'sameday' )-1;
format new_end yymmdd10.;

put _all_;
run;

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
  • 2 replies
  • 678 views
  • 0 likes
  • 3 in conversation