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

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.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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