I have table a, one variable is dummy variable with “Y”*or *”N”.
If “N”, count unique patients and unique providers by provider’s phone number;
if “Y”, join by provider’s ID with table b, then count unique patients and unique providers.
Here is my code. It is tedious. Do we have one PROC SQL step to fulfill all what I want or a simpler way? Thanks!
data yes no ;
set a;
if PRV_SPECIAL_HANDLING='Y' then output yes;
if PRV_SPECIAL_HANDLING='N' then output no;
run;
proc sort data=yes out=yes1; by prv_id; run;
proc sort data=b nodupkey out=HANDLING; by prv_id; run;
data merge_yes;
merge yes1(in=a) handling(in=b);
by prv_id;
if a;
run;
proc sort data=no out=no1; by prv_id; run;
data final;
set no1 merge_yes;
by prv_id;
run;
proc sql;
create table CN_uni_prv as
select PROV_PHONE,
count(unique(prv_id)) as uni_prv,
count(unique(pt_id)) as uni_pt
from final
group by PROV_PHONE ;
quit;
The answer is “yes”. I am finding it a bit hard to follow your tables and columns. Assuming the set of providers is different, then perform the counts on the ones without the phone number and then union this with the counts where you join to the second table.
The query would look something like:
If there is an overlap, then you need to do the union before the group by:
I replaced the
count(unique)withcount(distinct). I’m pretty sure SAS supports the latter and it is standard SQL.