BookmarkSubscribeRSS Feed
renjithr
Quartz | Level 8

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.

6 REPLIES 6
Haikuo
Onyx | Level 15

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

Linlin
Lapis Lazuli | Level 10

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

shivas
Pyrite | Level 9

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

art297
Opal | Level 21

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

;

Linlin
Lapis Lazuli | Level 10

Thank you Art!

your code works great after changing " format all days start end mmddyy10.;" to "format alldays start end mmddyy10.;"

art297
Opal | Level 21

Fixed!  Thanks for spotting it!

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!

What is Bayesian Analysis?

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.

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
  • 6 replies
  • 1856 views
  • 0 likes
  • 5 in conversation