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,
TimeSeries allows you to specify the range:
Proc Expand and possible Proc TimeSeries both offer options.
TimeSeries allows you to specify the range:
Thanks Reeza. that's what I ws looking for. Thanks for solution.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.