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.
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.
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.