Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8835369
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:14:44+00:00 2026-06-14T09:14:44+00:00

I have table a , one variable is dummy variable with Y* or *

  • 0

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;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T09:14:45+00:00Added an answer on June 14, 2026 at 9:14 am

    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:

    select PROV_PHONE, count(distinct prv_id) as uni_prv, count(distinct pt_id) as uni_pt
    from a
    where PRV_SPECIAL_HANDLING='N'
    group by prov_phone
    union all
    select PROV_PHONE, count(distinct prv_id) as uni_prv, count(distinct pt_id) as uni_pt
    from a join
         b
         on a.prv_id = b.prv_id
    where PRV_SPECIAL_HANDLING='Y'
    group by prov_phone
    

    If there is an overlap, then you need to do the union before the group by:

    select PROV_PHONE, count(distinct prv_id) as uni_prv, count(distinct pt_id) as uni_pt
    from ((select PROV_PHONE, prv_id, pt_id
           from a
           where PRV_SPECIAL_HANDLING='N'
           group by prov_phone
          ) union all
          (select PROV_PHONE, b.prv_id, b.pt_id
           from a join
                b
                on a.prv_id = b.prv_id
           where PRV_SPECIAL_HANDLING='Y'
          )
         ) t
     group by prov_phone
    

    I replaced the count(unique) with count(distinct). I’m pretty sure SAS supports the latter and it is standard SQL.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a classified_id variable which matches one document in a MySql table. I
I have a table that contains in one column a variable length delimited string
I have a table with 3 columns containing a variable number of records based
I have table and one global variable in appdelegate class. I store all date
I have table with one of the columns as date in 'YYYY-MM-DD' format. Can
Hi I have table in one td i have text and in another td
I have one table which contains events and dates, and another which contains the
I have one table that has two fields - ID1 and ID2 ID1 can
I have one table having ID and other attributes. How can I get list
I have one table that has sales records and another table that has additional

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.