BookmarkSubscribeRSS Feed
lmtamina
Obsidian | Level 7

Hi,

 

I am a beginner in SAS and I do not have formal training yet but know SQL .I am also new in the SAS community board.  I am using PROC SQL to pull data from our libraries. I created to 2 tables and grouped some fields to get the total  amount and total unit count. When I tried created the summary table with the totals in it, I am not getting  accurate results, the aggregate totals are duplicating. Please see codes and results below:

Greatly appeciate any assistance. Thank you in advance.

 

options compress=yes;

proc sql;

CREATE TABLE FSF_GLOBAL_COST as

 

select

a.medclm_case_key,

a.modality,

sum(a.ctrct_alloc_allow_icob_amt) as TOTAL_GLOBAL_COST

from umxa1861.usi_caseclaims_medicare_fsf as a

group by

 

a.medclm_case_key,

a.modality;

quit;

options compress=yes;

proc sql;

CREATE TABLE FSF_TC_COUNT as

 

select

a.statecode,

a.prov_tax_id,

a.providername,

a.medclm_case_key,

a.modality,

sum(a.serv_unit_cnt) as TOTAL_UNIT_CNT

from umxa1861.usi_caseclaims_medicare_fsf as a

where a.cpt_mod_cd not in('26')

group by

 

a.statecode,

a.prov_tax_id,

a.providername,

a.medclm_case_key,

a.modality;

quit;

 

 

options compress=yes;

proc sql;

CREATE TABLE FSF_UNITCOST as

 

select

a.statecode,

a.prov_tax_id,

a.providername,

a.medclm_case_key,

a.modality,

sum(TOTAL_GLOBAL_COST) as total_Cost,

sum(TOTAL_UNIT_CNT) as total_units

from FSF_TC_COUNT as a

left join FSF_GLOBAL_COST as b

on a.medclm_case_key = b.medclm_case_key

and a. modality = b. modality;

quit;

 

 

 

4 REPLIES 4
utrocketeng
Quartz | Level 8

i am not seeing your results, but i think you are saying that you are getting duplicate a.medclm_case_key/ a.modality combinations.  if that is the case, try adding DISTINCT to your select statement:

proc sql;

CREATE TABLE FSF_GLOBAL_COST as

 

select DISTINCT

a.medclm_case_key,

a.modality,

sum(a.ctrct_alloc_allow_icob_amt) as TOTAL_GLOBAL_COST

from umxa1861.usi_caseclaims_medicare_fsf as a

group by

 

a.medclm_case_key,

a.modality;

quit;

ballardw
Super User

Example data is always helpful. Change any critical values to preserve privacy and such. The example data should replicate the behavior of the full data.

Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.

 

Your FSF_TC_COUNT data set was grouped by state and provider so when you left joint on the claim (guessing) and modality total each state/provider appears in the output with the total. So if you want a total cost to match the count you would have to group the totals by the same grouping variables to use the approach you show.

 

Or provide a description of what you are actually attempting do. Some Example data with the desired result may be the best way. Likely you would only need to show two or three case_key/modality in the first and two or three state/ providers per matching case_key/modality.

lmtamina
Obsidian | Level 7

Thank you for your replies. I am trying to match only the medclm_case_key and modality variables from my FSF_TC_Count table with the medclm_case_key and modality variables on the FSF_Global Cost table. Below is a dummy sample of  my current result:

 

State Code    Prov_tax_id      ProviderName                 Medclm_Case_key      Modality     Total Cost      Total Units

MI                        12345         Provider1                        8800000011                MRI             100000            10

TN                       34567         Provider2                        8800000022                 CT              100000            10

FL                        89101         Provider3                        8800000033                PET            100000            10

SC                       12687         Provider4                        8800000044                MRI             100000            10

.

.

 

I am expecting sample results below .Should not be duplicating the total cost and total units;

State Code    Prov_tax_id      ProviderName                 Medclm_Case_key      Modality     Total Cost      Total Units

MI                        12345         Provider1                        8800000011                MRI             500                   2

TN                       34567         Provider2                        8800000022                 CT              800                   4

FL                        89101         Provider3                        8800000033                PET            10000               5

SC                       12687         Provider4                        8800000044                MRI             2000                 8

 

Appreciate your assistance. Thank you once again

.

.

.

.

 

ballardw
Super User

Example of both starting data sets will help.

 

And to allow us to test code against that data: Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 885 views
  • 0 likes
  • 3 in conversation