Help using Base SAS procedures

Mean of a count

Reply
Occasional Contributor
Posts: 9

Mean of a count

I have data with several variables including store_id, location, and product_cat.  Store_Id ranges from 1-8, location ranges from 1-9 (representing outside, entrance etc.), and product_cat ranges from 1-8 (representing candy, cereal, etc).  I need the mean number of "displays/counts" per store by location and product_cat.  I'm unsure how to transform this data to get the correct information. 

Trusted Advisor
Posts: 1,345

Re: Mean of a count

Posted in reply to billfriend

Please show how the data is arranged now, as in a SAS data step.  Then are layout of what the desired results would look like.

 

Help us help you.

Super User
Posts: 23,776

Re: Mean of a count

Posted in reply to billfriend

Try a summary procedure such as PROC MEANS/SUMMARY.

 

You can add multiple variables into the BY statement, and SAS will break down the analysis by the variables in the BY statement. 

 

Basic tutorials/demo is here:

https://github.com/statgeek/SAS-Tutorials/blob/master/proc_means_basic.sas

Occasional Contributor
Posts: 9

Re: Mean of a count

This is great, thank you!  Quick question-I am not reporting by store. My table shells look like this:

Locations

Mean (SD)

Range

Outside

 

 

Entrance

 

 

EndCap A

 

 

EndCap B

 

 

Aisle

 

 

Edge

 

 

Checkout side

 

 

Checkout edge

 

 

Island

 

 

Food Product Categories

Mean (SD)

Range

Cereal

 

 

Candy

 

 

Chips

 

 

Cookies

 

 

Fruits and Vegetables

 

 

Fruit Drink

 

 

Soda

 

 

Beverages

 

 

I am confused as to what to report.  I can't just take the "by STORE_ID;" out.

Super User
Posts: 23,776

Re: Mean of a count

Posted in reply to billfriend

Post some sample data and your expected output. Please post as a data step, see instructions here:

https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat...

 

You can also google a paper called ‘creating complex reports’ by Cynthia Zender that walks through how to create presentation ready tables. 

Occasional Contributor
Posts: 9

Re: Mean of a count

I'm having a hard time getting this to work.  I have SAS version 9.4.  I downloaded the macro and have it opened in my SAS; I don't use macros that are this complicated very often, so it's a bit confusing.  Do I edit the top line?

%macro data2datastep(mydatasetname?,lib,outlib,file,obs,fmt,lbl);

Super User
Posts: 23,776

Re: Mean of a count

Posted in reply to billfriend

Don’t touch the macro code. Run it once and then close that program. 

Run through the instructions exactly first and then try it on your data.

Occasional Contributor
Posts: 9

Re: Mean of a count

I ran the macro, closed it. I don't have SAS University Edition so I am confused about Autoexe.
I tried to run:
>%data2datastep(mydatasetname,sashelp,,10)
This kept giving me an error, sashelp.mydatasetname does not exit.

Also, I'm not worried about creating complex tables, I'm just unsure what to fill those table shells with. Thank you!
Super User
Posts: 23,776

Re: Mean of a count

Posted in reply to billfriend

 

Top of the post:

 

%data2datastep(dsn, lib, file, obs);

 

dsn = input data set name, required

 

lib = library where input data set resides, optional

 

file = name of output file, optional

 

obs = number of obs to include in the data step, optional 

 

Lib, the second parameter is the library where the data set is stored. I'm assuming your data set is not in the SASHELP library but most likely the WORK library. Just leave it empty and it should work.

Ask a Question
Discussion stats
  • 8 replies
  • 146 views
  • 0 likes
  • 3 in conversation