BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
baystanil
Calcite | Level 5

Hello SAS Community, 

Query is on use of class and by statement in proc means.

By and class statement is applicable for character type data.

 

I have used sample data shoe in SASHELP folder and using SAS Studio.

region and product are the charater data I am interested in, for sales total.

I am interested to have result table of sales sales for each region by product and then second table for each product by region.

Refer attached 'proc means example.sas' file for code.

 

I am able to see the result table for product by region correctly, meaning all products in single table separated for/by each region.

while result table for region by product includes only africa region rather than all region in table seperated for/by each product.

Refer attached 'proc means example-results.pdf' for results table.

 

Can you help why is it so?

1 ACCEPTED SOLUTION

Accepted Solutions
Shmuel
Garnet | Level 18

You could find the reason to the issue in the log:

ERROR: Data set WORK.SHOES is not sorted in ascending sequence. The current BY group has Product = Women's Dress and the next BY 
 group has Product = Boot.

Add  appropriate sort before running any proc with BY statement.

View solution in original post

2 REPLIES 2
Shmuel
Garnet | Level 18

You could find the reason to the issue in the log:

ERROR: Data set WORK.SHOES is not sorted in ascending sequence. The current BY group has Product = Women's Dress and the next BY 
 group has Product = Boot.

Add  appropriate sort before running any proc with BY statement.

ballardw
Super User

@baystanil wrote:

Hello SAS Community, 

By and class statement is applicable for character type data.

 

CLASS and BY variables can be variables of any type. Always. It is a good idea to use them with variables that make sense as categories.

It is very common to use date variables as CLASS variables because changing the format in the code will create different groups based on the formatted variable.

 

One of the advantages of CLASS variables is that SAS will do the sort when they are not sorted before the procedure. There is a processing time penalty and extremely large number of class variable/level combinations may exceed resources.

 

You might also consider a different procedure to generate the output since you apparently do not have a need for output data sets. Consider:

proc tabulate data=sashelp.shoes format=best10.;
   class region product;
   var sales;
   table region,
         sales
   ;
   table product,
         sales
   ;
run;

Proc tabulate will create the summaries using the formatted values of the class variables.

 

Caveat: Proc tabulate will by default discard any record with missing values for any of the class variables unless the option /missing is provided on the class statement.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 448 views
  • 2 likes
  • 3 in conversation