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?
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.
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.
@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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: