BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hello ,

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

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

/*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"]
;
run;

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 ,
mark
2 REPLIES 2
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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.
Cynthia_sas
SAS Super FREQ
Hi:
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:
[pre]
proc format;
value ag_fmt 11-13 = 'Teens'
14-16 = 'Young Adults';
run;

proc tabulate data=sashelp.class;
class sex age;
var height;
table sex*age,
height*mean;
format age ag_fmt.;
run;
[/pre]

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:
[pre]
ERROR: The type of name (DateofSale) is unknown.
ERROR: The type of name (UnitsSold) is unknown.
[/pre]

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:
[pre]
proc format;
value ag_fmt 11-13 = 'Teen'
14-16='Young Adult';

value $gend 'F' = 'Female'
'M' = 'Male';
run;
[/pre]

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

As someone has already explained, a format that starts with a '$' is meant to be used with a CHARACTER variable.explained in this posting:
http://support.sas.com/forums/thread.jspa?threadID=8896&tstart=0

In that previous posting, you defined 2 NUMERIC formats:
[pre]

proc format;
value prdfmt 1='Period1'
2='Period2';
value wkfmt 1='Week1'
2='Week2'
3='Week3'
4='Week4';
run;
[/pre]

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

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.;
[/pre]

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.

cynthia

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 3551 views
  • 0 likes
  • 3 in conversation