DATA Step, Macro, Functions and more

Weekly Sum/Aggregate: Week begins on a Tuesday

Reply
Occasional Contributor
Posts: 7

Weekly Sum/Aggregate: Week begins on a Tuesday

Hi,

 

I'm new to SAS programing so any assistance will be great. 

 

I have a data set which contains daily (day var) revenue, visit and order participation websites. It looks something like this:  

 

web_IdStart_DateEnd_DateDayRevenue_ParticipationVisitsOrders_ParticipationUnits_Participation
17666182-Jun-1513-Jul-152-Jun-1503221155
17666182-Jun-1513-Jul-153-Jun-159592831790
17666182-Jun-1513-Jul-154-Jun-1502661566
17666182-Jun-1513-Jul-155-Jun-1502681337
17666182-Jun-1513-Jul-156-Jun-150259746
17666182-Jun-1513-Jul-157-Jun-154543001372
17666182-Jun-1513-Jul-158-Jun-1503901458
17666182-Jun-1513-Jul-159-Jun-1503522165
17666182-Jun-1513-Jul-1510-Jun-1503041763
17666182-Jun-1513-Jul-1511-Jun-1503041054
17666182-Jun-1513-Jul-1512-Jun-15662911684
17666182-Jun-1513-Jul-1513-Jun-150233839
17666182-Jun-1513-Jul-1514-Jun-1503381870
189547117-Mar-154-May-1517-Mar-15010600
189547117-Mar-154-May-1517-Mar-1508341652
189547117-Mar-154-May-1518-Mar-1509600
189547117-Mar-154-May-1518-Mar-15858812917
189547117-Mar-154-May-1519-Mar-1508900
189547117-Mar-154-May-1519-Mar-150726413
189547117-Mar-154-May-1520-Mar-1506551459
189547117-Mar-154-May-1520-Mar-152007111
189547117-Mar-154-May-1521-Mar-1508300
189547117-Mar-154-May-1521-Mar-1507031132
189547117-Mar-154-May-1522-Mar-15011100
189547117-Mar-154-May-1522-Mar-1507681336
189547117-Mar-154-May-1523-Mar-1516911712
189547117-Mar-154-May-1523-Mar-15657701411
189547117-Mar-154-May-1524-Mar-1508800
189547117-Mar-154-May-1524-Mar-150639833

 

What I need to do is sum the totals for Revenue_Participation,  Visits , Orders_Participation and Units_Participation by week for each website (web_Id) during the specified campaign date range - between Start_date and end_date based off the day var.

 

I’d have a var call Week in the datset. The tricky part is the week does not begin on a Sunday or Monday, it begins on a tuesday and ends on monday.  I'm looking for an ouput which looks like this (the counts don't match to the above): 

 

web_IdWeek(starts on Tuesday)Start_DateEnd_DateRevenue_ParticipationVisitsOrders_ParticipationUnits_Participation
17666186/9/20152-Jun-1513-Jul-15054589888
17666186/16/20152-Jun-1513-Jul-155565365363
17666186/23/20152-Jun-1513-Jul-15998886658783

 

 I have been experimenting with code like this.

data week;

set have;

week_of=intnx('week',day,0,'B');

format week_of date9.; run;

 

Any help will be  appreciated. Thanks! 

Super User
Posts: 17,912

Re: Weekly Sum/Aggregate: Week begins on a Tuesday

week_of=intnx('week',day,0,'B');

Above generates a Sunday, adding 2 will give you Tuesday.

week_of=intnx('week',day,0,'B') + 2;
Ask a Question
Discussion stats
  • 1 reply
  • 183 views
  • 0 likes
  • 2 in conversation