Hello,
I have two variables,start date and end date ,I want to create a data set with allthe dates between those two variables.please let me know how to create it.
Thanks in advance.
Given the sample data:
data have;
input date date9. v1;
format date date9.;
cards;
05jan2012 1
25jan2012 2
;
two options: 1) simpler approach, if you have ETS:
proc timeseries data=have out=want;
id date interval=day;
var v1;
run;
2) If you don't have ETS:
data want (drop=_:);
set have;
set have (firstobs=2 keep=date rename=date=_date)
have (obs=1 drop=_all_);
output;
do while (intck('day',date,_date)>1) ;
call missing (v1);
date=intnx('day',date,1);
output;
end;
run;
Haikuo
try this:
data have;
informat start mmddyy10. end mmddyy10.;
format start mmddyy10. end mmddyy10.;
input id start end ;
cards;
1 01/05/2012 01/20/2012
2 02/05/2012 02/10/2012
;
data want(drop=i);
set have;
do i=1 to (end-start);
days=intnx('day',start,i,'s');
output;
end;
format days mmddyy10.;
run;
proc print;run;
Linlin
Hi,
data have;
input startdate enddate;
informat startdate enddate date9.;
format startdate enddate date9.;
cards;
01jan2012 15jan2012
01feb2012 05feb2012
;
run;
data want;
set one;
x=intck('day',startdate,enddate);
do i =1 to x;
y=intnx('day',enddate,-i);
output;format y date9.;
end;
drop x i;
run;
Thanks,
Shiva
Using Linlin's data, why not something as simple as (untested):
data have;
informat start end mmddyy10.;
format allindays start end mmddyy10.;
input id start end ;
do alldays=start to end;
output;
end;
cards;
1 01/05/2012 01/20/2012
2 02/05/2012 02/10/2012
;
Thank you Art!
your code works great after changing " format all days start end mmddyy10.;" to "format alldays start end mmddyy10.;"
Fixed! Thanks for spotting it!
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.