From: mark on
Hello ,

I've used the folllowing code :-

/* Find Revenues for the different period sales*/
data revenues;
set sales;
if Laptopmodel="AT3600" then do;
if warranty=1 then
revenue=UnitsSold*(1199.99+39);
if warranty=0 then
revenue=UnitsSold*1199.99;
end;
else if Laptopmodel="AP3965" then do;
if DateofSale < '15/11/2009' and warranty=1 then
revenue=UnitsSold*(699.99+39);
else if DateofSale < '15/11/2009' and warranty=0 then
revenue=UnitsSold*(699.99);
if DateofSale >= '15/11/2009' and DateofSale < '29/11/2009' and
warranty=1 then
revenue=UnitsSold*(499.99+39);
else if DateofSale >= '15/11/2009' and DateofSale < '29/11/2009' and
warranty=0 then
revenue=UnitsSold*(499.99);
end;
if DateofSale < '15/11/2009' then period='period1';
else period='period2';
proc print data = revenues;
run;


/*The same day delivery transactions*/
data SameDayDelivery;
set sales;
IF TimeofSale <= '15:00' THEN SameDayDelivery = 'Yes';
ELSE SameDayDelivery = 'No';
TITLE ' Same Day Deilvery';
proc print data = SameDayDelivery;
run;


/*Weekly sales*/
data week;
set sales;
IF DateofSale >= "01/11/2009" and DateofSale < "08/11/2009" THEN
Week = "Week1";
Else IF DateofSale >= "08/11/2009" and DateofSale < "15/11/2009" THEN
Week = "Week2";
Else IF DateofSale >= "15/11/2009" and DateofSale < "22/11/2009"
THEN
Week = "Week3";
ELSE IF DateofSale >= "22/11/2009" and DateofSale < "29/11/2009"
THEN
Week = "Week4";
Proc Print data = week;
Run;

/*sort by week*/
proc sort data = week;
By Week;
proc print data = week;
RUN;

/*total number of units sold over two period time*/

title;
footnote;
options missing=' ';
proc tabulate data=PrepForTabulate noseps;
class LaptopModel Week SameDayDelivery;
var UnitsSold;
label DateofSale='Week of Sale';
label SameDayDelivery='Same Day Delivery';
label week='Week of Sale';
table (Week all='Total Week')*SameDayDelivery all='Total',
(LaptopModel all='Total')*UnitsSold*
(sum='Sold'*f=8. pctsum<SameDayDelivery all>*f=comma5.1)
;
run;

The last code gives log error , if i dont include ' Week ' in my class
varaible then it works fine, but with 'Week ' it gives error :-

746 class LaptopModel Week SameDayDelivery;
ERROR: Variable WEEK not found.
747 var UnitsSold;
748 label DateofSale='Week of Sale';
749 label SameDayDelivery='Same Day Delivery';
750 label week='Week of Sale';
751 table (Week all='Total Week')*SameDayDelivery all='Total',
(LaptopModel all='Total')*UnitsSold*
752 (sum='Sold'*f=8. pctsum<SameDayDelivery all>*f=comma5.1)
753 ;
754 run;

NOTE: The SAS System stopped processing this step because of errors.

I need to find a breakdown of the units sold and the revenues all 4
weeks .

Kind Regards,
mark
From: Jack Hamilton on
The message is telling you that there is no variable named Week in the input data set. SAS is rarely wrong about that kind of thing.

You create the variable Week in data set Week, but your proc tabulate uses data set PrepForTabulate.

Also, you should get into the habit of ending your data steps with the RUN statement. It makes the code easier to follow.



--
Jack Hamilton
jfh(a)alumni.stanford.org
Caelum non animum mutant qui trans mare currunt.

On Mar 5, 2010, at 3:41 pm, mark wrote:

> Hello ,
>
> I've used the folllowing code :-
>
> /* Find Revenues for the different period sales*/
> data revenues;
> set sales;
> if Laptopmodel="AT3600" then do;
> if warranty=1 then
> revenue=UnitsSold*(1199.99+39);
> if warranty=0 then
> revenue=UnitsSold*1199.99;
> end;
> else if Laptopmodel="AP3965" then do;
> if DateofSale < '15/11/2009' and warranty=1 then
> revenue=UnitsSold*(699.99+39);
> else if DateofSale < '15/11/2009' and warranty=0 then
> revenue=UnitsSold*(699.99);
> if DateofSale >= '15/11/2009' and DateofSale < '29/11/2009' and
> warranty=1 then
> revenue=UnitsSold*(499.99+39);
> else if DateofSale >= '15/11/2009' and DateofSale < '29/11/2009' and
> warranty=0 then
> revenue=UnitsSold*(499.99);
> end;
> if DateofSale < '15/11/2009' then period='period1';
> else period='period2';
> proc print data = revenues;
> run;
>
>
> /*The same day delivery transactions*/
> data SameDayDelivery;
> set sales;
> IF TimeofSale <= '15:00' THEN SameDayDelivery = 'Yes';
> ELSE SameDayDelivery = 'No';
> TITLE ' Same Day Deilvery';
> proc print data = SameDayDelivery;
> run;
>
>
> /*Weekly sales*/
> data week;
> set sales;
> IF DateofSale >= "01/11/2009" and DateofSale < "08/11/2009" THEN
> Week = "Week1";
> Else IF DateofSale >= "08/11/2009" and DateofSale < "15/11/2009" THEN
> Week = "Week2";
> Else IF DateofSale >= "15/11/2009" and DateofSale < "22/11/2009"
> THEN
> Week = "Week3";
> ELSE IF DateofSale >= "22/11/2009" and DateofSale < "29/11/2009"
> THEN
> Week = "Week4";
> Proc Print data = week;
> Run;
>
> /*sort by week*/
> proc sort data = week;
> By Week;
> proc print data = week;
> RUN;
>
> /*total number of units sold over two period time*/
>
> title;
> footnote;
> options missing=' ';
> proc tabulate data=PrepForTabulate noseps;
> class LaptopModel Week SameDayDelivery;
> var UnitsSold;
> label DateofSale='Week of Sale';
> label SameDayDelivery='Same Day Delivery';
> label week='Week of Sale';
> table (Week all='Total Week')*SameDayDelivery all='Total',
> (LaptopModel all='Total')*UnitsSold*
> (sum='Sold'*f=8. pctsum<SameDayDelivery all>*f=comma5.1)
> ;
> run;
>
> The last code gives log error , if i dont include ' Week ' in my class
> varaible then it works fine, but with 'Week ' it gives error :-
>
> 746 class LaptopModel Week SameDayDelivery;
> ERROR: Variable WEEK not found.
> 747 var UnitsSold;
> 748 label DateofSale='Week of Sale';
> 749 label SameDayDelivery='Same Day Delivery';
> 750 label week='Week of Sale';
> 751 table (Week all='Total Week')*SameDayDelivery all='Total',
> (LaptopModel all='Total')*UnitsSold*
> 752 (sum='Sold'*f=8. pctsum<SameDayDelivery all>*f=comma5.1)
> 753 ;
> 754 run;
>
> NOTE: The SAS System stopped processing this step because of errors.
>
> I need to find a breakdown of the units sold and the revenues all 4
> weeks .
>
> Kind Regards,
> mark