I have a question regarding SAS. We have a table crimes
consisting of crimes (one crime per row with many more informations such as the article of the criminal law or the date).
Date Article
——————————————-
2019-01-01 146
2019-01-01 122
2019-01-01 123
2019-01-01 123
2019-01-02 160
...
Every year we receive a questionnaire to fill out how many crimes have been committed in certain categories (e.g. fraud, homicides, etc.). Unfortunately, the categories in this questionnaire are not the same as our own categories (articles of the criminal law). So we have to define, which articles fall into which survey-category. These informations are stored in at table called definitions
.
In the example below there are two articles (110, 111) that could be summarized as „theft“ and three articles that could be summarized as „assault“:
Category Article Query
———————————————————————-
Theft 110 select count(*) from crimes where article = 110
Theft 111 select count(*) from crimes where article = 111
Robbery 130 select count(*) from crimes where article = 113
Assault 140 select count(*) from crimes where article = 140
Assault 141 select count(*) from crimes where article = 141
Assault 146 select count(*) from crimes where article = 146
In our database crimes
we also have a column „article“. The goal is now to read how many crimes there are.
As a result I would like to have a table like this, that gives me the number of crimes per category (the categories defined as in the table definitions
):
Category Count
———————————————————
Theft 10,038
Robbery 503
Assault 1,200
The question is now: What‘s the best way to get the desired result?