Help using Base SAS procedures

How to create a data set with all days of a month?

Reply
Frequent Contributor
Posts: 122

How to create a data set with all days of a month?

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.

Respected Advisor
Posts: 3,124

Re: How to create a data set with all days of a month?

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=_Smiley Happy;

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

Super Contributor
Posts: 1,636

Re: How to create a data set with all days of a month?

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

Super Contributor
Posts: 349

Re: How to create a data set with all days of a month?

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

PROC Star
Posts: 7,363

Re: How to create a data set with all days of a month?

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

;

Super Contributor
Posts: 1,636

Re: How to create a data set with all days of a month?

Thank you Art!

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

PROC Star
Posts: 7,363

Re: How to create a data set with all days of a month?

Fixed!  Thanks for spotting it!

Ask a Question
Discussion stats
  • 6 replies
  • 352 views
  • 0 likes
  • 5 in conversation