Help using Base SAS procedures

Proc Tabulate

Posts: 0

Proc Tabulate

Hello All ,

I'm using PROC TABULATE. I have pasted some sample data below as I have nearly 400+ observations.

Transaction Timeof Laptop Units
ID DateofSale Sale Model Sold Warranty Week

RX000476 23/11/2009 09:40:09 AP3965 1 0 Week4
RX000475 23/11/2009 23:28:37 AP3965 1 0 Week4
RX000474 23/11/2009 06:50:40 AP3965 1 0 Week4
RX000473 23/11/2009 09:47:16 AP3965 1 0 Week4
RX000472 23/11/2009 05:35:33 AP3965 1 0 Week4
RX000471 23/11/2009 14:26:35 AT3600 1 0 Week4
RX000470 23/11/2009 07:33:28 AT3600 1 0 Week4

Objective is - To find the # UnitsSold of each kind of LaptopModel - AP3965 & AT3600 for each of the four weeks spread over one month.

The code I used :-

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;

Data Tabulate;
set sales;
proc tabulate data=tables f=dollar8.;
class week Laptopmodel;
var UnitsSold;
table week*Laptopmodel,
Unitssold*Mean=" ";
proc print data = Tabulate;

The log -

522 proc tabulate data=tables f=dollar8.;
ERROR: File WORK.TABLES.DATA does not exist.
523 class week Laptopmodel;
ERROR: No data set open to look up variables.
ERROR: No data set open to look up variables.
524 var UnitsSold;
ERROR: No data set open to look up variables.
525 table week*Laptopmodel,
526 Unitssold*Mean=" ";
527 run;

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

Kindly suggest what chnage do I need in the 2nd code.

Kind Regards ,
Regular Contributor
Posts: 165

Re: Proc Tabulate

You really need to work out your logic in that data step.

Have you even writen anything for proc tabulate?
Posts: 8,740

Re: Proc Tabulate

The &GT; in your code is causing your code not to post correctly. As previously recommended, this posting explains how to use &ampGT; as the way to show >, and [pre] and [/pre] to surround your code.毙

But, if you are willing to read some user group papers on PROC TABULATE, the TABLE statement needed to achieve your report is fairly straightforward.

I generally recommend that you draw a little picture of what you want your output table to look like, because, when you're starting out, that helps you decide which variables go in ROW versus COL dimensions in the TABLE statement. The model syntax for PROC TABULATE is shown below using SASHELP.SHOES:
proc tabulate;
class region product;
var sales;
table region all,

which "translates" to:
proc tabulate data=dataset;
class classvar (or list multiple);
var analysis_var (or list multiple);
table row_dimension,

For this PROC TABULATE, REGION and PRODUCT are going to set the groups and SALES will be used for analysis. REGION will be in the ROW dimension and PRODUCT will be in the COL dimension. The statistic that I will get for PRODUCT is the average sales for each product. If, on the other hand, I wanted a simple count of sales, then either of these programs would produce that number, depending on whether I wanted to actually count the number of SALES (the first example) or the number of observations for each product (the second examle). In some instances, the two tabulates could give the same results, in other instances, they might give different results (depending on your data):

proc tabulate f=comma6.;
class region product;
var sales;
table region all,

proc tabulate f=comma6.;
class region product;
table region all,

It is going to be impossible for you to learn how to use PROC TABULATE effectively without reading about how the CLASS, VAR and TABLE statements need to work together.

Super Contributor
Posts: 359

Re: Proc Tabulate


Come on. You have not applied any of the things we have given you. You still are not converting your dates to SAS dates.

Frankly, if this is for a class, you need to do your own homework. If this is for work, you are not qualified.
Ask a Question
Discussion stats
  • 3 replies
  • 4 in conversation