BookmarkSubscribeRSS Feed
walshy
Calcite | Level 5

I have a dataset with counts of a number of different places e.g.

newcastle  24

sunderland 46

south shields 3

seaburn 67

durham 119

chester-le-street 43

wallsend 85

heaton 12

north shields 14

I'm wanting to combine a number of the rows together as they're in the same area, and also want the new single row to display the sum of all of the counts put together.

For example: wallsend, heaton, north shields and newcastle could all be classed simply as newcastle with a count of (24+85+12+14)

Is there a way to do this?

Also if the data was all a similar name such as: 1 newcastle

                                                                      2 newc

                                                                      3 newcastle united

                                                                      4 newcastle council

as an example is there also a way to combine all these entries and the sum of there counts into one row named newcastle????

Hope you can help

Thanks

1 REPLY 1
Fugue
Quartz | Level 8

Regarding grouping:

proc sql;

     create table want as

     select ( case when CITY in ('Wallsend', 'Heaton', . . . .more names . . . ) then 'Newcastle'

                           when CITY in (. . .  .  some other towns to group together ) then 'Something else'

                           . . . . more when statements . . .

                         else 'All others'

                   end ) as town_grp

     from have

     group by town_grp

;

quit;

This won't address your need to group similiarly-spelled towns together. For this, you could consider using the SOUNDEX, SPEEDIS, COMPLEV, or COMPGED functions.

Here is one link (of many on the web) giving an overview of the different comparison functions available in SAS.

http://www.nesug.org/Proceedings/nesug11/ap/ap07.pdf

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 916 views
  • 0 likes
  • 2 in conversation