Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- SAS Procedures
- /
- Proc Tabulate

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

03-04-2010 10:23 AM

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

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

03-04-2010 10:59 AM

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

Have you even writen anything for proc tabulate?

Have you even writen anything for proc tabulate?

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

03-04-2010 11:21 AM

Hi:

The > in your code is causing your code not to post correctly. As previously recommended, this posting explains how to use &GT; 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

The > in your code is causing your code not to post correctly. As previously recommended, this posting explains how to use &GT; 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=

class

var

table

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

03-04-2010 11:25 AM

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.

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.