BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
nkm123
Calcite | Level 5

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,

1 ACCEPTED SOLUTION
4 REPLIES 4
Reeza
Super User

Proc Expand and possible Proc TimeSeries both offer options.

nkm123
Calcite | Level 5
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.
nkm123
Calcite | Level 5

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

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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