-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathProject_New.sas
2178 lines (1860 loc) · 63.9 KB
/
Project_New.sas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*For Grocery Store*/
libname sun 'C:\Users\wxs171530\Desktop';
data sun.b1;
infile 'C:\Users\wxs171530\Desktop\blades\blades_PANEL_GR_1114_1165.dat' firstobs = 2 expandtabs;
input panid week units outlet $ dollars iri_key colupc;
format colupc 16.;
run;
libname sun 'C:\Users\wxs171530\Desktop';
data sun.b2;
infile 'C:\Users\wxs171530\Desktop\blades\ads_demo1.csv' dlm=',' dsd missover firstobs=2;
input panid pantype Combined_PreTaxIncome Family_Size HH_race Type_of_Residential_Possession County HH_age HH_edu HH_occ Age_Group_Male Education_Level_Male Occupation_code_Male Male_Working_Hour Male_smoke Age_Group_Female Education_Level_Female Occupation_Code_Female Female_Working_Hour Female_smoke Number_Dogs Number_Cats Children_Group Marital_status Language Number_TVs Number_TVs_Cable Year Hisp_flag Hisp_cat HH_Race_2 HH_Race_3 Microwave_owned Zipcode Fipscode market_zipcode IRI_Geography_Number Ext_fact;
run;
libname sun 'C:\Users\wxs171530\Desktop';
data sun.b3;
infile 'C:\Users\wxs171530\Desktop\blades\blades_groc_1114_1165.dat' firstobs=2;
input iri_key week sy ge vend item units dollars F $ D pr;
run;
data q1;
set sun.b1;
run;
data q2;
set sun.b2;
drop pantype county Number_Dogs Number_Cats Language Hisp_flag Hisp_cat HH_Race_2 Microwave_owned zipcode IRI_Geography_Number Fipscode market_zipcode ext_fact HH_Age HH_Occ HH_Edu Male_smoke Female_smoke HH_Race_3 Year;
run;
data q3;
set sun.b3;
drop sy ge vend;
run;
/*Merging Datasets*/
proc sort data=q1;
by panid;
proc sort data=q2;
by panid;
data combined;
merge q1 (in=inq1) q2 (in=inq2);
by panid;
if inq1 and inq2;
run;
proc sort data=combined;
by iri_key week;
proc sort data=q3;
by iri_key week;
run;
data combined;
merge combined (in=incomb1) q3 (in=inq3);
by iri_key week;
if incomb1 and inq3;
run;
/*For Drug Store*/
libname sun 'C:\Users\wxs171530\Desktop';
data sun.b4;
infile 'C:\Users\wxs171530\Desktop\blades\blades_PANEL_DR_1114_1165.dat' firstobs = 2 expandtabs;
input panid week units outlet $ dollars iri_key colupc;
format colupc 16.;
run;
libname sun 'C:\Users\wxs171530\Desktop';
data sun.b5;
infile 'C:\Users\wxs171530\Desktop\blades\blades_drug_1114_1165.dat' firstobs = 2;
input iri_key week sy ge vend item units dollars F $ D pr;
run;
data q4;
set sun.b4;
run;
data q5;
set sun.b5;
drop sy ge vend;
run;
/*Merging Datasets*/
proc sort data=q4;
by panid;
proc sort data=q2;
by panid;
data combined2;
merge q4 (in=inq4) q2 (in=inq2);
by panid;
if inq4 and inq2;
run;
proc sort data=combined2;
by iri_key week;
proc sort data=q5;
by iri_key week;
run;
data combined2;
merge combined2 (in=incomb2) q5 (in=inq5);
by iri_key week;
if incomb2 and inq5;
run;
data combined;
set combined combined2;
run;
/*proc import out=sun.b6
datafile = 'C:\Users\wxs171530\Desktop\blades\prod_blades.csv'
dbms=csv replace;
getnames=yes;
datarow=2;
run;*/
data SUN.B6 ;
%let EFIERR = 0; /* set the ERROR detection macro variable */
infile 'C:\Users\wxs171530\Desktop\blades\prod_blades.csv' delimiter = ',' MISSOVER DSD
lrecl=13106 firstobs=2 ;
informat L1 $17. ;
informat L2 $10. ;
informat L3 $21. ;
informat L4 $21. ;
informat L5 $60. ;
informat L9 $32. ;
informat Level best32. ;
informat UPC $17. ;
informat colupc best32. ;
informat SY best32. ;
informat GE best32. ;
informat VEND best32. ;
informat ITEM best32. ;
informat _STUBSPEC_1777RC $70. ;
informat VOL_EQ best32. ;
informat PRODUCT_TYPE $15. ;
informat FORM $12. ;
informat PACKAGE $20. ;
informat FLAVOR_SCENT $7. ;
informat MECHANISM $12. ;
informat TREATMENT $7. ;
informat SHAPE $7. ;
format L1 $17. ;
format L2 $10. ;
format L3 $21. ;
format L4 $21. ;
format L5 $60. ;
format L9 $32. ;
format Level best12. ;
format UPC $17. ;
format colupc best12. ;
format SY best12. ;
format GE best12. ;
format VEND best12. ;
format ITEM best12. ;
format _STUBSPEC_1777RC $70. ;
format VOL_EQ best12. ;
format PRODUCT_TYPE $15. ;
format FORM $12. ;
format PACKAGE $20. ;
format FLAVOR_SCENT $7. ;
format MECHANISM $12. ;
format TREATMENT $7. ;
format SHAPE $7. ;
input
L1 $
L2 $
L3 $
L4 $
L5 $
L9 $
Level
UPC $
colupc
SY
GE
VEND
ITEM
_STUBSPEC_1777RC $
VOL_EQ
PRODUCT_TYPE $
FORM $
PACKAGE $
FLAVOR_SCENT $
MECHANISM $
TREATMENT $
SHAPE $
;
run;
data q6;
set sun.b6;
drop L1 L3 L4 L9 Level UPC SY GE _stubspec_1777RC flavor_scent;
format colupc 16.;
run;
/*Investigating Dataset*/
/*proc sort data=combined;
by colupc;
proc sort data=q3;
by colupc;
data combined1;
merge combined (in=incolupc1) q3 (in=incolupc3);
by colupc;
if not incolupc1 then put colupc 'no associated product';
if not incolupc3 then put colupc 'no associated buyer';
run;*/
/*Merging Dataset based on what can be accounted for*/
proc sort data=combined;
by colupc;
proc sort data=q6;
by colupc;
data combined1;
merge combined (in=incolupc1) q6 (in=incolupc6);
by colupc;
if incolupc1 and incolupc6;
run;
/*proc sort data=combined1;
by panid week colupc; run;
proc print data=combined1; run; quit;
proc freq data=combined1 noprint;
tables week*L5 / nocol nopercent out=pct_row;
run;*/
/*proc export data=work.x2
outfile='C:\Users\wxs171530\Desktop\blades\market_share.csv'
dbms=csv
replace;
run;*/
/*proc import out=sun.b7
datafile = 'C:\Users\wxs171530\Desktop\blades\market_share.csv'
dbms=csv replace;
getnames=yes;
datarow=2;
run;*/
data combined1;
set combined1;
if missing(Number_TVs) then Number_TVs = .;
if missing(Number_TVs_Cable) then Number_TVs_Cable = .;
run;
/*proc freq data=combined1;
table L5;
run;data q7;
set sun.b7;
run;
proc sort data=combined1;
by week L5;
proc sort data=q7;
by week L5;
data combined1;
merge combined1 (in=in1) q7 (in=inq7);
by week L5;
if in1 and inq7;
run;*/
/*proc print data=combined1; run; quit;*/
/*Grouping Data together*/
data a1;
set combined1;
if L5='BIC' then brand=1;
else if L5='BIC CLASSIC ORIGINAL' then brand=1;
else if L5='BIC CLASSIC SENSITIVE' then brand=1;
else if L5='BIC LADY SHAVER' then brand=1;
else if L5='BIC METAL' then brand=1;
else if L5='BIC PASTEL' then brand=1;
else if L5='BIC PLUS' then brand=1;
else if L5='BIC SOFTWIN' then brand=1;
else if L5='BIC TWIN SELECT SENSITIVE SKI' then brand=1;
else if L5='BIC TWIN SELECT SILKY TOUCH' then brand=1;
else if L5='BIC TWIN SELECT TOUGH BEARD' then brand=1;
else if L5='FLICKER' then brand=0;
else if L5='GEM' then brand=0;
else if L5='GILLETTE' then brand=2;
else if L5='GILLETTE AGILITY' then brand=2;
else if L5='GILLETTE ATRA' then brand=2;
else if L5='GILLETTE ATRA PLUS' then brand=2;
else if L5='GILLETTE CUSTOM PLUS' then brand=2;
else if L5='GILLETTE CUSTOM PLUS FOR WOME' then brand=2;
else if L5='GILLETTE DAISY PLUS' then brand=2;
else if L5='GILLETTE GOOD NEWS' then brand=2;
else if L5='GILLETTE GOOD NEWS PIVOT PLUS' then brand=2;
else if L5='GILLETTE GOOD NEWS PLUS' then brand=2;
else if L5='GILLETTE MACH3' then brand=2;
else if L5='GILLETTE SENSOR' then brand=2;
else if L5='GILLETTE SENSOR EXCEL' then brand=2;
else if L5='GILLETTE SENSOR EXCEL WOMEN' then brand=2;
else if L5='GILLETTE SENSOR FOR WOMEN' then brand=2;
else if L5='GILLETTE TRAC II' then brand=2;
else if L5='GILLETTE TRAC II PLUS' then brand=2;
else if L5='GILLETTE VENUS' then brand=2;
else if L5='PAL' then brand=0;
else if L5='SCHICK' then brand=3;
else if L5='SCHICK FX DIAMOND' then brand=3;
else if L5='SCHICK INJECTOR' then brand=3;
else if L5='SCHICK PERSONAL TOUCH' then brand=3;
else if L5='SCHICK PROTECTOR' then brand=3;
else if L5='SCHICK SILK EFFECTS' then brand=3;
else if L5='SCHICK SILK EFFECTS PLUS' then brand=3;
else if L5='SCHICK SLIM TWIN' then brand=3;
else if L5='SCHICK SUPER II' then brand=3;
else if L5='SCHICK TRACER' then brand=3;
else if L5='SCHICK TRACER FX' then brand=3;
else if L5='SCHICK TRACER FX SPORT' then brand=3;
else if L5='SCHICK XTREME III' then brand=3;
else if L5='TREET' then brand=0;
else brand = 0;
run;
proc freq data=a1;
table brand; run;
data a1;
set a1;
if brand = 0 then delete; run;
data a1;
set a1;
if L5='BIC' then gender= "unisex";
else if L5='BIC CLASSIC ORIGINAL' then gender="male";
else if L5='BIC CLASSIC SENSITIVE' then gender="male";
else if L5='BIC LADY SHAVER' then gender="female";
else if L5='BIC METAL' then gender="male";
else if L5='BIC PASTEL' then gender="female";
else if L5='BIC PLUS' then gender="male";
else if L5='BIC SOFTWIN' then gender="unisex";
else if L5='BIC TWIN SELECT SENSITIVE SKI' then gender="male";
else if L5='BIC TWIN SELECT SILKY TOUCH' then gender="female";
else if L5='BIC TWIN SELECT TOUGH BEARD' then gender="male";
else if L5='FLICKER' then gender="unisex";
else if L5='GEM' then gender="male";
else if L5='GILLETTE' then gender="unisex";
else if L5='GILLETTE AGILITY' then gender="female";
else if L5='GILLETTE ATRA' then gender="male";
else if L5='GILLETTE ATRA PLUS' then gender="male";
else if L5='GILLETTE CUSTOM PLUS' then gender="male";
else if L5='GILLETTE CUSTOM PLUS FOR WOME' then gender="female";
else if L5='GILLETTE DAISY PLUS' then gender="female";
else if L5='GILLETTE GOOD NEWS' then gender="male";
else if L5='GILLETTE GOOD NEWS PIVOT PLUS' then gender="male";
else if L5='GILLETTE GOOD NEWS PLUS' then gender="male";
else if L5='GILLETTE MACH3' then gender="male";
else if L5='GILLETTE SENSOR' then gender="male";
else if L5='GILLETTE SENSOR EXCEL' then gender="male";
else if L5='GILLETTE SENSOR EXCEL WOMEN' then gender="female";
else if L5='GILLETTE SENSOR FOR WOMEN' then gender="female";
else if L5='GILLETTE TRAC II' then gender="male";
else if L5='GILLETTE TRAC II PLUS' then gender="male";
else if L5='GILLETTE VENUS' then gender="female";
else if L5='PAL' then gender="male";
else if L5='SCHICK' then gender="unisex";
else if L5='SCHICK FX DIAMOND' then gender="unisex";
else if L5='SCHICK INJECTOR' then gender="male";
else if L5='SCHICK PERSONAL TOUCH' then gender="female";
else if L5='SCHICK PROTECTOR' then gender="male";
else if L5='SCHICK SILK EFFECTS' then gender="female";
else if L5='SCHICK SILK EFFECTS PLUS' then gender="female";
else if L5='SCHICK SLIM TWIN' then gender="unisex";
else if L5='SCHICK SUPER II' then gender="male";
else if L5='SCHICK TRACER' then gender="male";
else if L5='SCHICK TRACER FX' then gender="unisex";
else if L5='SCHICK TRACER FX SPORT' then gender="male";
else if L5='SCHICK XTREME III' then gender="unisex";
else if L5='TREET' then gender="male";
else if L5='VALET' then gender="male";
else gender=0;
drop L5;
run;
proc print data=a1 (obs=10);run;
proc format;
value brand 1 = 'Bic';
value brand 2 = 'Gillette';
value brand 3 = 'Schick';
run;
data a2;
set a1;
where Combined_PreTaxIncome > 0;
run;
proc freq data = a2;
table Combined_PreTaxIncome;
run;
data a2;
set a2;
rename Combined_PreTaxIncome = combined_inc;
run;
proc format;
value combined_inc 1 = '0-9.9';
value combined_inc 2 = '10-11.9';
value combined_inc 3 = '12-14.9';
value combined_inc 4 = '15-19.9';
value combined_inc 5 = '20-24.9';
value combined_inc 6 = '25-34.9';
value combined_inc 7 = '35-44.9';
value combined_inc 8 = '45-54.9';
value combined_inc 9 = '55-64.9';
value combined_inc 10 = '65-74.9';
value combined_inc 11 = '75-99.9';
value combined_inc 12 = '>=100';
run;
/*Creating Factors*/
proc freq data = a2;
tables family_size;
run;
proc format;
value family_size 1 = 'One';
value family_size 2 = 'Two';
value family_size 3 = 'Three';
value family_size 4 = 'Four';
value family_size 5 = 'Five';
value family_size 6 = 'Six +';
run;
data a3;
set a2;
if HH_Race = 3 then Hispanic = 1;
else Hispanic = 0;
drop HH_Race;
run;
proc format;
value Hispance 1 = 'Yes';
value Hispanic 0 = 'No';
run;
proc freq data=a3;
tables type_of_residential_possession;
run;
data a3;
set a3;
if type_of_residential_possession = 1 then resident = 0;
else resident = 1;
drop type_of_residential_possession;
run;
proc format;
value resident 0 = 'Renter';
value resident 1 = 'Owner';
run;
/*proc contents data=a3; run;*/
/*data a3;
set a3;
drop age_group_female;
drop age_group_male;
drop education_level_female;
drop education_level_male;
drop female_working_hour;
drop male_working_hour;
drop occupation_code_female;
drop occupation_code_male;
run;*/
/*proc contents data=a3; run;*/
data a3;
set a3;
if Children_Group = 0 then children = 0;
else if Children_Group = 8 then children = 0;
else children = 1;
drop Children_Group;
run;
proc format;
value children 0 = 'No';
value children 1 = 'Yes';
run;
proc freq data=a3;
table marital_status;
run;
data a3;
set a3;
if marital_status = 0 then delete;
run;
proc format;
value Marital_status 1 = 'Single';
value Marital_status 2 = 'Married';
value Marital_status 3 = 'Divorced';
value Marital_status 4 = 'Widowed';
value Marital_status 5 = 'Seperated';
run;
proc contents data=a3; run;
data a4;
set a3;
drop family_size;
drop mechanism;
drop number_tvs;
drop number_tvs_cable;
drop shape;
drop treatment;
drop vend;
run;
proc freq data = a4;
tables d;
run;
proc freq data = a4;
tables f;
run;
proc freq data = a4;
tables package;
run;
data a4;
set a4;
if package = 'BAG' then pack = 1;
else if package = 'PEG BAG' then pack = 1;
else if package = 'PLASTIC PEG BAG' then pack = 1;
else if package = 'BLISTER PACK' then pack = 2;
else if package = 'PEG CARD BLISTER PCK' then pack = 2;
else pack = 3;
run;
proc format;
value pack 1 = 'Bag';
value pack 2 = 'Pack';
value pack 3 = 'Others';
run;
/*Investigating Product type = Razor Blades*/
proc freq data=a4;
where product_type = 'RAZOR BLADE';
table L2*product_type;
run;
proc freq data=a4;
table product_type;
run;
data a4;
set a4;
drop product_type;
run;
data a4;
set a4;
if L2 = 'CARTRIDGES' then type = 0;
else type = 1;
run;
proc format;
value type 0 = 'Cartridges';
value type 1 = 'Disposable';
run;
/*Testing out Demographics based on Chi-sq*/
data a4;
set a4;
length brand_name $10.;
if brand = 3 then brand_name = 'Schick';
if brand = 2 then brand_name = 'Gillette';
if brand = 1 then brand_name = 'BIC';
run;
data chi1;
set a4;
run;
proc freq data=chi1;
tables brand_name*age_group_male / chisq;
run;
proc freq data=chi1;
tables brand_name*age_group_female / chisq;
run;
data chi2;
set chi1;
if education_level_male = 1 then education_level_male = 2;
if education_level_female = 1 then education_level_female = 2;
run;
proc freq data=chi2;
tables brand_name*education_level_male / chisq;
run;
proc freq data=chi2;
tables brand_name*education_level_female / chisq;
run;
proc freq data=chi2;
tables brand_name*occupation_code_male / chisq;
run;
proc freq data=chi2;
tables brand_name*occupation_code_female / chisq;
run;
/*Visualizing Data*/
title "Break-down of Total Dollars by Brand and Age Group Female";
proc sgplot data=a4;
vbar age_group_female / group=brand_name response=dollars seglabel seglabelattrs=(size=8);
run;
title "Break-down of Total Dollars by Brand and Age Group Male";
proc sgplot data=a4;
vbar age_group_male / group=brand_name response=dollars seglabel seglabelattrs=(size=8);
run;
data a4;
set a4;
Disposable = 0; if L2 = 'DISPOSABLE' then Disposable = dollars;
Cartridges = 0; if L2 = 'CARTRIDGES' then Cartridges = dollars;
run;
title1 'Distribution of Dollars Sales from Disposable and Cartridges';
proc sgplot data=a4;
histogram Disposable / fillattrs=graphdata1 transparency=0.5 binstart=40 binwidth=10;
density Disposable / lineattrs=graphdata1;
histogram Cartridges / fillattrs=graphdata2 transparency=0.3 binstart=40 binwidth=10;
density Cartridges / lineattrs=graphdata2;
keylegend / location=inside position=topright noborder across=2;
yaxis grid;
xaxis display=(nolabel) values=(0 to 200 by 10);
run;
proc freq data=a4;
table brand_name*gender / out=trans1 (keep= trans1 brand_name gender count) nopercent nocum;
run;
proc sgplot data=trans1;
vbar brand_name / group=gender response=count groupdisplay=cluster seglabel seglabelattrs=(size=8);
xaxis display=(nolabel noticks);
yaxis label='Count of Units Sold';
keylegend / title='Gender';
run;
data a4;
set a4;
drop brand_name;
drop Disposable;
drop Cartridges;
run;
/*Descriptive Analysis*/
proc corr data=a4;
var units dollars;
run;
/*Which drugs/grocery sells more?*/
proc univariate data = a4 normal;
var dollars;
run;
/*Removing Outliers*/
/*top 99% and bottom 1%*/
data a5;
set a4;
if dollars >= 110.460 then delete;
if dollars <= 1.19 then delete;
run;
data trans7;
set a4;
if dollars >= 20 then delete;
run;
data trans7;
set trans7;
length brand_name $10.;
if brand = 3 then brand_name = 'Schick';
if brand = 2 then brand_name = 'Gillette';
if brand = 1 then brand_name = 'BIC';
run;
proc print data=trans7 (obs=10); run;
title1 'Boxplot of Dollars earned during Price Reduction for the different Brands';
proc sgplot data=trans7;
vbox dollars / category=pr group=brand_name;
xaxis label="Brands";
keylegend / title="Sales Dollars";
run;
proc univariate data = a5 normal;
var dollars;
histogram dollars / normal;
run;
/*must do linear, log-linear and log-log models*/
/*Encoding dummy variables*/
proc print data = a5 (obs=10); run;
/*data a5;
set a5;
unit_blade_price = dollars/vol_eq;
run;*/
proc sort data=a5;
by panid week brand;
run;
data a5;
set a5;
by panid week brand;
if First.brand then total_units=units;
total_units + units;
run;
proc print data=a5 (obs=10);run;
data a5;
set a5;
brand_bic = 0 ; if brand = 1 then brand_bic = 1;
brand_gil = 0 ; if brand = 2 then brand_gil = 1;
brand_sch = 0 ; if brand = 3 then brand_sch = 1;
run;
proc freq data = a5;
table form; run;
data a5;
set a5;
single = 0 ; if form = 'SINGLE BLADE' then single = 1;
twin = 0 ; if form = 'TWIN BLADE' then twin = 1;
triple = 0 ; if form = 'TRIPLE BLADE' then triple = 1;
run;
proc freq data = a5;
table package; run;
data a5;
set a5;
pack_bag = 0 ; if pack = 1 then pack_bag = 1;
pack_pack = 0 ; if pack = 2 then pack_pack = 1;
pack_oth = 0 ; if pack = 3 then pack_oth = 1;
run;
proc freq data = a5;
table outlet; run;
data a5;
set a5;
outlet_new = 0 ; if outlet = 'GR' then outlet_new = 1;
run;
proc freq data = a5;
table F;
run;
data a5;
set a5;
f_none = 0 ; if F = 'NONE' then f_none = 1;
f_a = 0 ; if F = 'A' then f_a = 1;
f_a1 = 0 ; if F = 'A+' then f_a1 = 1;
f_b = 0 ; if F = 'B' then f_b = 1;
f_c = 0 ; if F = 'C' then f_c = 1;
run;
proc freq data = a5;
tables d;
run;
data a5;
set a5;
d_no = 0 ; if d = 0 then d_no = 1;
d_min = 0 ; if d = 1 then d_min = 1;
d_maj = 0 ; if d = 2 then d_maj = 1;
run;
proc freq data = a5;
tables pr;
run;
proc freq data = a5;
tables combined_inc;
run;
data a5;
set a5;
inc_1 = 0; if combined_inc = 1 then inc_1 = 1;
inc_2 = 0; if combined_inc = 2 then inc_2 = 1;
inc_3 = 0; if combined_inc = 3 then inc_3 = 1;
inc_4 = 0; if combined_inc = 4 then inc_4 = 1;
inc_5 = 0; if combined_inc = 5 then inc_5 = 1;
inc_6 = 0; if combined_inc = 6 then inc_6 = 1;
inc_7 = 0; if combined_inc = 7 then inc_7 = 1;
inc_8 = 0; if combined_inc = 8 then inc_8 = 1;
inc_9 = 0; if combined_inc = 9 then inc_9 = 1;
inc_10 = 0; if combined_inc = 10 then inc_10 = 1;
inc_11 = 0; if combined_inc = 11 then inc_11 = 1;
inc_12 = 0; if combined_inc = 12 then inc_12 = 1;
run;
proc freq data=a5;
tables marital_status;
run;
data a5;
set a5;
marital_status1=0; if marital_status = 1 then marital_status1 = 1;
marital_status2=0; if marital_status = 2 then marital_status2 = 1;
marital_status3=0; if marital_status = 3 then marital_status3 = 1;
marital_status4=0; if marital_status = 4 then marital_status4 = 1;
marital_status5=0; if marital_status = 5 then marital_status5 = 1;
run;
/*data a5;
set a5;
by panid week brand;
weighted_priceblade = (unit_blade_price*units)/total_units;
weighted_pricereduce = (pr*units)/total_units;
weighted_displayno = (d_no*units)/total_units;
weighted_displaymin = (d_min*units)/total_units;
weighted_displaymaj = (d_maj*units)/total_units;
weighted_featureno = (f_none*units)/total_units;
weighted_featurea = (f_a*units)/total_units;
weighted_featurea1 = (f_a1*units)/total_units;
weighted_featureb = (f_b*units)/total_units;
weighted_featurec = (f_c*units)/total_units;
weighted_form1 = (single*units)/total_units;
weighted_form2 = (twin*units)/total_units;
weighted_form3 = (triple*units)/total_units;
weighted_packbag = (pack_bag*units)/total_units;
weighted_packpack = (pack_pack*units)/total_units;
weighted_packoth = (pack_oth*units)/total_units;
weighted_brand1 = (brand_bic*units)/total_units;
weighted_brand2 = (brand_gil*units)/total_units;
weighted_brand3 = (brand_sch*units)/total_units;
weighted_brand0 = (brand_oth*units)/total_units;
run;*/
data a5;
set a5;
by panid week brand;
weighted_priceblade = ((dollars*(units/total_units))/vol_eq);
weighted_pricereduce = pr*(units/total_units);
weighted_displayno = d_no*(units/total_units);
weighted_displaymin = d_min*(units/total_units);
weighted_displaymaj = d_maj*(units/total_units);
weighted_featureno = f_none*(units/total_units);
weighted_featurea = f_a*(units/total_units);
weighted_featurea1 = f_a1*(units/total_units);
weighted_featureb = f_b*(units/total_units);
weighted_featurec = f_c*(units/total_units);
weighted_form1 = single*(units/total_units);
weighted_form2 = twin*(units/total_units);
weighted_form3 = triple*(units/total_units);
weighted_packbag = pack_bag*(units/total_units);
weighted_packpack = pack_pack*(units/total_units);
weighted_packoth = pack_oth*(units/total_units);
weighted_brand1 = brand_bic*(units/total_units);
weighted_brand2 = brand_gil*(units/total_units);
weighted_brand3 = brand_sch*(units/total_units);
weighted_type = type*(units/total_units);
run;
proc print data=a5 (obs=10);run;
data a5;
set a5;
by panid week brand;
if First.brand then total_weightedtype=0;
total_weightedtype + weighted_type;
if Last.brand;
run;
data a5;
set a5;
by panid week brand;
if First.brand then total_weightedprice=0;
total_weightedprice + weighted_priceblade;
if Last.brand;
run;
data a5;
set a5;
by panid week brand;
if First.brand then total_weightedbrand1=0;
total_weightedbrand1 + weighted_brand1;
if Last.brand;
run;
data a5;
set a5;
by panid week brand;
if First.brand then total_weightedbrand2=0;
total_weightedbrand2 + weighted_brand2;
if Last.brand;
run;
data a5;
set a5;
by panid week brand;
if First.brand then total_weightedbrand3=0;
total_weightedbrand3 + weighted_brand3;
if Last.brand;
run;
proc print data=a5 (obs=10); run;
data a5;
set a5;
by panid week brand;
if First.brand then total_weightedprice=0;
total_weightedprice + weighted_priceblade;
if Last.brand;
run;
data a5;
set a5;
by panid week brand;
if First.brand then total_weightedpr=0;
total_weightedpr + weighted_pricereduce;
if Last.brand;
run;
data a5;
set a5;
by panid week brand;
if First.brand then total_weighteddno=0;
total_weighteddno + weighted_displayno;
if Last.brand;
run;
data a5;
set a5;
by panid week brand;
if First.brand then total_weighteddmin=0;
total_weighteddmin + weighted_displaymin;
if Last.brand;
run;
data a5;
set a5;
by panid week brand;
if First.brand then total_weighteddmaj=0;
total_weighteddmaj + weighted_displaymaj;
if Last.brand;
run;
data a5;
set a5;
by panid week brand;
if First.brand then total_weightedfno=0;
total_weightedfno + weighted_featureno;
if Last.brand;
run;
data a5;
set a5;
by panid week brand;
if First.brand then total_weightedfa=0;
total_weightedfa + weighted_featurea;
if Last.brand;
run;
data a5;
set a5;
by panid week brand;
if First.brand then total_weightedfa1=0;
total_weightedfa1 + weighted_featurea1;
if Last.brand;
run;
data a5;
set a5;
by panid week brand;
if First.brand then total_weightedfb=0;
total_weightedfb + weighted_featureb;
if Last.brand;
run;
data a5;
set a5;
by panid week brand;
if First.brand then total_weightedfc=0;
total_weightedfc + weighted_featurec;
if Last.brand;
run;
data a5;
set a5;
by panid week brand;
if First.brand then total_weightedform1=0;
total_weightedform1 + weighted_form1;