I have two data sets in SAS 9.4. One is type_list
, which contains 14 different account types. The other is account_list
, which contains thousands of accounts.
I'm trying to get a list of all types with a count of how many accounts in each type meet certain criteria. Crucially, if there are zero matching accounts, I'd like a row with zero in the output. For example:
TYPE ACCOUNTS
type-1 104
type-2 0
type-3 56
... ...
Here's the query I'm using:
PROC SQL;
CREATE TABLE summary AS
SELECT
type_list.type,
COUNT(account_list.account_number) AS accounts
FROM type_list
LEFT JOIN account_list
ON type_list.type = account_list.type
WHERE account_list.curr_balance > 1000
GROUP BY type_list.type;
QUIT;
The actual output I'm getting doesn't have a row for types that don't have any matching accounts. For example:
TYPE ACCOUNTS
type-1 104
type-3 56
... ...