Help using Base SAS procedures

Proc Tabulate

Not applicable
Posts: 0

Proc Tabulate

Hello ,

Could anyone please help me in the code error, i tried a lot. I used :-

PROC Format;
VALUE $SameDayDelivery 1 = 'Yes'
2 = 'No';

/*Proportion of daily transactions that qualify for same day delivery*/
proc tabulate data = weekly_sales_revenues f = comma6.;
CLASS LaptopModel ;
VAR SameDayDelivery ;
LABEL SameDayDelivery='Same Day Delivery';
TABLE DateofSale*SameDayDelivery ALL='Total'*LaptopModel all='Total',UnitsSold
*( MEAN STD MIN MAX sum='Sold'*f=8. pctsum='in %'*f=comma5.1)
/box=[label="Daily Transactions"]

Error -

ERROR: Variable SameDayDelivery in list does not match type prescribed for this list.

kindly suggest I need to find the proprtion of the Yes and No in SameDayDelivery

regards ,
Super Contributor
Super Contributor
Posts: 3,176

Re: Proc Tabulate

Posted in reply to deleted_user
Use PROC CONTENTS to analyze the SAS variables in your table -- you are attempting to use a CHARACTER type variable as a VAR statement (analysis) variable. You must convert the variable from character-type to numeric-type.

Scott Barry
SBBWorks, Inc.
Posts: 9,373

Re: Proc Tabulate

Posted in reply to deleted_user
It would be useful to see the WHOLE log, not just a single error message. I see several problems in your code.

It looks like you want to use SameDayDelivery as a CLASS variable (to set categories and see the 'YES' and 'NO' in the row dimension, perhaps?) but then you define the numeric variable in a VAR statement. Numeric variables can be used in a CLASS statement, especially when you want to use a NUMERIC variable to set categories -- this is an acceptable use in PROC TABULATE. For example, with SASHELP.CLASS. In this PROC TABULATE step, I want to use AGE to set groups, so it appears in a CLASS statement:
proc format;
value ag_fmt 11-13 = 'Teens'
14-16 = 'Young Adults';

proc tabulate data=sashelp.class;
class sex age;
var height;
table sex*age,
format age ag_fmt.;

You are also using DateofSale and UnitsSold in a TABLE statement, but do not have either variable listed in either the CLASS or VAR statement. You should be receiving an error message that looks something like this:
ERROR: The type of name (DateofSale) is unknown.
ERROR: The type of name (UnitsSold) is unknown.

The TABULATE documentation is very clear that ALL the variables listed in the TABLE statement must be listed in either a CLASS or a VAR statement. That's because PROC TABULATE needs to know how you intend to use the variable.

You will also have problems with the SameDayDelivery variable. It is in a VAR statement. I assume that it is a NUMERIC variable. It you want to use a format with a NUMERIC variable, then the format must be a NUMERIC format. If you look in the documentation, you will see that there are two types of formats which you can define in a VALUE statement -- character and numeric, as shown below:
proc format;
value ag_fmt 11-13 = 'Teen'
14-16='Young Adult';

value $gend 'F' = 'Female'
'M' = 'Male';

To use these formats, SAS would expect a format statement like this:
format age ag_fmt. sex $gend.;

As someone has already explained, a format that starts with a '$' is meant to be used with a CHARACTER variable.explained in this posting:

In that previous posting, you defined 2 NUMERIC formats:

proc format;
value prdfmt 1='Period1'
value wkfmt 1='Week1'

But then you had a format statement:
[pre]FORMAT Period $prdfmt. Week $wkfmt.;

Which generated an ERROR message. The ERROR message happened because there was no reason to put a '$' in front of a NUMERIC format name. You didn't define $PRDFMT or $WKFMT, you defined PRDFMT and WKFMT. The '$' means something to PROC FORMAT and to SAS. The correct FORMST statement would have been:
[pre]FORMAT Period prdfmt. Week wkfmt.;

Again, I suggest you read the documentation for the CLASS, VAR and TABLE statements with PROC TABULATE to see how to use variables for analysis and variables to set categories. Then I suggest you read the documentation on how to define and use formats appropriately.

Ask a Question
Discussion stats
  • 2 replies
  • 3 in conversation