DATA Step, Macro, Functions and more

Filling missing dates in dataset

Accepted Solution Solved
Reply
Contributor
Posts: 30
Accepted Solution

Filling missing dates in dataset

Hi, I have a dataset for all store id with sale date and quantity purchased. Sales Date is the date when qty purchased and it could be any date of month.  Now I need to create month data where all store ID should have all date of month (ex Jan 2016 then 01JAN2016 to 31jAN2016). Most of stores don't have qty purchsed throughout the months so may have only 5 rowas instaed of 31 rows and I need to create a record with 0 qty where sale date is not present in storedata for specific store id.

 

Here is what I have

 

data storeData;

informat sale_date date9.;

format sale_date date9.;

input store_id sale_date qty ;

datalines;

101 '01Jan2016'd 10

101 '03JAN2016'd 20

101 '07JAN2016'd 5

101 '20JAN2016'd 5

102 '03JAN2016'd 20

102 '05JAN2016'd 20

;

run;

 

here is what I want

 

proc sort data=storeData out=uni(keep=store_id) nodupkey;

by store_id;

run;

data dumpData;

set uni;

format sale_date date9.;

do i = '01JAN2016'd to '31JAN2016'd;

sale_date = i;

output;

drop i;

end;

run;

 

data salesDataMonth;

merge storeData dumpData;

by store_id sale_date;

if qty = . then qty =0;

run;

 

Is there any other way to fill missing dates from store data ?

 

Thanks,


Accepted Solutions
Solution
‎03-23-2016 03:03 PM
Super User
Posts: 19,822

Re: Filling missing dates in dataset


All Replies
Super User
Posts: 19,822

Re: Filling missing dates in dataset

Proc Expand and possible Proc TimeSeries both offer options.

Contributor
Posts: 30

Re: Filling missing dates in dataset

My understanding is proc expand will only fill from start of sale date and what is last date of sale date for particular store id and qty will be taken from previous observation. It won't what I need as I need data from 01Jan2016 till 31Jan2016 for all store id and qty would be 0 if this is not sale date in original data. Hope this helps.
Solution
‎03-23-2016 03:03 PM
Super User
Posts: 19,822

Re: Filling missing dates in dataset

Contributor
Posts: 30

Re: Filling missing dates in dataset

Thanks Reeza. that's what I ws looking for. Thanks for solution.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 794 views
  • 0 likes
  • 2 in conversation