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

Hello, I am working with a data set that is a report about users. 

The relevant columns are:

  1. Category
  2. Zip Code
  3. Active
  4. Revenue

An example of this data is

category | zip code | active | revenue

- "unknown" | 12345 | true | 900

- "Other" | 12345 | true | 1000

Because of the sources of this data, I want to combine "unknown" and "other" so the report accounts for all the unknown categories. I would like to combine this and aggregate where appropriate so that the result looks like:

category | zip code | active | revenue

- "Unknown\Other" | 12345 | true | 1900

How would I do this and bonus points if I can do this without creating a new table.

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
andreas_lds
Jade | Level 19

Define a format, use proc summary (code is untested):

proc format:
  value $categoryfmt
    "unknown", "Other" = "Unknown/Other"
  ;
run;

proc summary data=have nway;
  class category zip_code active;
  var revenue;
  output out=result(drop= _:) sum=;
run;

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26

Is this problem a table with only two rows, or is it a bigger table with many rows? If it is a bigger table with many rows, what are the rules for combining ... do we combine everything, or by zip code, or by active, or something else?

 

And the "aggregate" that you mention is really just a sum of the values under revenue? Or did you want somethign else done with revenue?

--
Paige Miller
andreas_lds
Jade | Level 19

Define a format, use proc summary (code is untested):

proc format:
  value $categoryfmt
    "unknown", "Other" = "Unknown/Other"
  ;
run;

proc summary data=have nway;
  class category zip_code active;
  var revenue;
  output out=result(drop= _:) sum=;
run;
ballardw
Super User

Groups created by a format such as @andreas_lds suggests would be honored by report procedures such as Proc Report or Tabulate, almost all the analysis procedures and most will work for graphing procedures.

 

The nice thing about using a Format instead of altering data is that a different format for a procedure can create different groupings based on single variables.. No actual change to the data set needed. This can be a significant time savings if working with largish data sets as the time needed to add new variables can get noticeable. Not to mention having to constantly add variables for new uses.

 

 

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!
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
  • 3 replies
  • 457 views
  • 2 likes
  • 4 in conversation