BookmarkSubscribeRSS Feed
westbestern
Obsidian | Level 7

Below is a table of my variables and some data. I want to aggregate the data by zipcode. How do I go about doing this?

westbestern_0-1649282811908.png

 

2 REPLIES 2
ballardw
Super User

Since most of those variables are basically categories by aggregate I have to assume count.

Do you need a data set for further manipulation or a report for people to read?

If you need a data set you need to provide some example of what the result would look like and rules.

 

I might start with something like:

Proc tabulate data=have;
   class zipcode county_name state_name age_cat;
   /* row based count*/
   table zipcode* (state_name county_name age_cat),n;
  /* crosstab */
   table  state_name county_name age_cat,
            zipcode*n
   ;
   /* nested cross tab */
   table  zipcode ,
            state_name*county_name*n
   ;
  /* ugly and quite possibly not very useful */
  table zipcode*age_cat,
          state_name * county_nam *n
  ;
run; 

First warning with Proc Tabulate, any record missing one or more of the Class variables is dropped from the summary by default. If you have missing values and want that level reported you add a /missing; option to Class statement with the variable(s) that may have missings.

You can dump a LOT of variables into a table statement, and many statistics, and the result may take some time to appear in a results window.

There are many other statistics you can request. Every where there is an N you could request percentages with Pctn, RowPctn, Colpctn, Reppctn or PagePctn.

The Comma separates dimensions: page (if there are 3), row, column. The * requests a nest, that means each level of the second variable or statistic follows each level of the first

If you have variables where requesting a mean, max, min, sum etc. would make sense, Those go on a Var statement and then request the statistics. 

There are many appearance options. This is a complex enough procedure SAS publishes a book just on Proc Tabulate.

Kurt_Bremser
Super User

I see only categories here. What do you want to "aggregate"?

Please do always supply example data in usable form (data step with datalines), so we can recreate it for developing/testing without having to make guesses about attributes (types, lengths, formats) and raw content.

Pictures are mostly useless.

SAS Innovate 2025: Call for Content

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 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

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