I have a dataset
Period Brand ID
Jan A X1
Jan A K1
Jan B CT2
Feb C X2
Feb A P4
I would like to do a distinct count of ID for each brand under each period. I tried using CASE WHEN in proc sql to count the distinct number in each period, but I am unsure of what to set for the else portion, since I am guessing SAS will also count the else part as a distinct item also. My code is as below:
proc sql;
create table items as
select period,
count(distinct case when brand="A" then ID else "." end) as Count_A,
count(distinct case when brand="B" then ID else "." end) as Count_B,
count(distinct case when brand="C" then ID else "." end) as Count_C
from Data
group by period;
quit;
I do understand that I am able to use sub query to construct each count variable also, but the code is likely to get very long and tedious.
Thank you!