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

Hi All,

My data is as shown below:

Promo_id Promotion_Start Promotion_End

10121 1/1/2015 1/14/2015

10129 1/1/2015 1/7/2015

So Requirement is to convert my data into weekly level:

Note: As per my client week start is of Monday to Sunday basis

Ex: Output of my data with new column need to be created "New Start week", "Count_of_Days" and "Calc_Reqd"

Promo_id Promotion_Start Promotion_End New_Start_week Count_of_Days "Calc_Reqd"

10121 1/1/2015 1/14/2015 12/29/2014 4 "4/7"

10121 1/1/2015 1/14/2015 1/5/2015 7 "7/7"

10121 1/1/2015 1/14/2015 1/12/2015 3 "3/7"

10129 1/1/2015 1/7/2015 12/29/2014 4 "4/7"

10129 1/1/2015 1/7/2015 1/5/2015 3 "3/7"

Thanks,

Ganesh K


1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

Code: Program

data have;
input Promo_id Promotion_Start : mmddyy10. Promotion_End : mmddyy10.;
format Promotion_Start Promotion_End mmddyy10.;
cards;
10121 1/1/2015 1/14/2015
10129 1/1/2015 1/7/2015
;
run;
data temp;
set have;
do date=Promotion_Start to Promotion_End ;
  New_Start_week=intnx('week.2',date,0,'b');
  output;
end;
format date New_Start_week mmddyy10.;
run;
data want;
set temp;
by Promo_id New_Start_week;
length Calc_Reqd $ 8;
if first.New_Start_week then Count_of_Days=0;
Count_of_Days +1;
if last.New_Start_week then do;
   Calc_Reqd=cats(Count_of_Days,'/7');
   output;
end;
drop date;
run;

View solution in original post

1 REPLY 1
Ksharp
Super User

Code: Program

data have;
input Promo_id Promotion_Start : mmddyy10. Promotion_End : mmddyy10.;
format Promotion_Start Promotion_End mmddyy10.;
cards;
10121 1/1/2015 1/14/2015
10129 1/1/2015 1/7/2015
;
run;
data temp;
set have;
do date=Promotion_Start to Promotion_End ;
  New_Start_week=intnx('week.2',date,0,'b');
  output;
end;
format date New_Start_week mmddyy10.;
run;
data want;
set temp;
by Promo_id New_Start_week;
length Calc_Reqd $ 8;
if first.New_Start_week then Count_of_Days=0;
Count_of_Days +1;
if last.New_Start_week then do;
   Calc_Reqd=cats(Count_of_Days,'/7');
   output;
end;
drop date;
run;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 1 reply
  • 366 views
  • 0 likes
  • 2 in conversation