Friday, January 14, 2011

A real problem to solve


A real problem is described as below:

These are TRP data for various laundry detergent ads.  The data comes in the MS Excel file and has the following format. 

F25-54 TRPs (Source: AdViews)
10/29/2006
11/5/2006
11/12/2006
11/19/2006
11/26/2006
12/3/2006
12/10/2006
Dinnertime :30
40
54
30
26
34
28
23
Dinnertime :15
22
18
25
21
14
15
16
Lightbulb :30
0
0
0
0
0
0
0
Lightbulb :15
0
0
0
0
0
0
0
Mug's Life :30
0
0
0
0
0
0
0
Mug's Life :15
0
0
0
0
0
0
0
Visits :30
3
1
5
5
4
5
1
Visits :15
4
4
1
5
5
3
4

Please write a SAS code to
(a)    Restructure data in the following format with the following variables. 
Week    Ad_Name  (DinnerTime, LightBulb etc)    Ad_Duration (30 or 15)   TRP (values in highlighted cells)
(b)   Remove all the records with value of 0.

(1): Answer for question (a)
options formdlim='-';
/******************************************************
  First, We need to construct the data as below
*******************************************************/
data test;
input TRPS $ 1-15 TRP1-TRP7;
cards;
Dinnertime :30       40     54     30     26     34     28     23
Dinnertime :15       22     18     25     21     14     15     16
Lightbulb :30 0      0      0      0      0      0      0
Lightbulb :15 0      0      0      0      0      0      0
Mug's Life :30       0      0      0      0      0      0      0
Mug's Life :15       0      0      0      0      0      0      0
Visits :30        3  1      5      5      4      5      1
Visits :15        4  4      1      5      5      3      4
;
run;

/**************************************************************
  Since it asks for AD_NAME and AD_Duration variables, which
  should be substracted from the first variable in the original
  data, we will do it with SCAN function
**************************************************************/
data set1;
  set test;
  delim=':';
  AD_Name=scan(trps,1,delim);
  AD_Duration=scan(trps,2,delim);
  drop delim trps;
run;

/**************************************************************
  Now we need to do the transpose from WIDE to LONG
**************************************************************/
data wanted (keep=Week AD_Name AD_Duration TRP);
   set set1;
   array atrp(7) trp1-trp7;
   do Week=1 to 7;
      TRP=atrp[Week];
         output;
   end;
run;


proc print data=&syslast;
run;

(2): Answer for question (b)
data zero_del;
   set wanted;
   where trp ^=0;
run;


proc print data=&syslast;
run;

No comments:

Post a Comment