Help using Base SAS procedures

Proc Tabulate

Reply
N/A
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;
Run;


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

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 ,
Mark
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?
SAS Super FREQ
Posts: 8,740

Re: Proc Tabulate

Hi:
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.
http://support.sas.com/forums/thread.jspa?messageID=27609毙

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.
http://www2.sas.com/proceedings/sugi30/243-30.pdf
http://www.ats.ucla.edu/stat/SAS/faq/tabulate.htm
http://www2.sas.com/proceedings/sugi30/258-30.pdf

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:
[pre]
proc tabulate data=sashelp.shoes;
class region product;
var sales;
table region all,
product*sales*mean;
run;
[/pre]

which "translates" to:
[pre]
proc tabulate data=dataset;
class classvar (or list multiple);
var analysis_var (or list multiple);
table row_dimension,
column_dimension;
run;
[/pre]

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):
[pre]

proc tabulate data=sashelp.shoes f=comma6.;
class region product;
var sales;
table region all,
product*sales*n;
run;


proc tabulate data=sashelp.shoes f=comma6.;
class region product;
table region all,
product*n;
run;
[/pre]

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.

cynthia
Super Contributor
Posts: 359

Re: Proc Tabulate

Mark;

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
  • 139 views
  • 0 likes
  • 4 in conversation