BookmarkSubscribeRSS Feed
_el_doredo
Quartz | Level 8

Hello Experts.

 

I want to join/merge sales and payment data. But, my summarization data is giving me duplicate sales amount. I dont want that

Datasets are below:

 

data payment;
infile cards dlm=',' dsd;
input ticketid :$20. Promo_Type Payment_Type :$12.
customer_id :$15. OrderDate :yymmdd10. Promo_Des :$30. Payment_Amt;
format OrderDate yymmdd10.;
cards;
A098765,,credit,C014532,2021-05-11,,500
A098765,,cash,C014532,2021-05-11,,100
A098765,,cash,C014532,2021-05-11,,180
A098765,,check,C014532,2021-05-11,,200
A098765,8360,Finance,C014532,2021-05-11,"36 months",5000
A098765,8600,Finance,C014532,2021-05-11,"60 months",3500
;
run;

data Sales;
infile cards dlm=',' dsd;
input ticketid :$20. ProductId :$20. customer_id :$15. OrderDate :yymmdd10. Sales_amt;
format OrderDate yymmdd10.;
cards;
A098765,"AX-14589",C014532,2021-05-11,1570
;
run;

 

I want my output like this

Assume Two filters are there.

1.Payment_Type

2.Promo_Type

Orderdate sum of sales_amt sum of payment_amt
11-05-2021 1570 9480

 

If i select select Payment_type as Cash means my output need to be

Orderdate sum of sales_amt sum of payment_amt
11-05-2021 0 280

 

If i select Promo_Type as 8360 means my output need to be

Orderdate sum of sales_amt sum of payment_amt
11-05-2021 0 5000

 

Can some one help me on this?

 

Thanks in Advance

4 REPLIES 4
PaigeMiller
Diamond | Level 26

@_el_doredo wrote:

 

I want to join/merge sales and payment data. 

 


Join/merge on what variables? You don't tell us, but we would need to know.

 

But, my summarization data is giving me duplicate sales amount. I dont want that

 

Show us your code.

--
Paige Miller
_el_doredo
Quartz | Level 8

@PaigeMiller 

 

This is my code

 

Proc sql;
create table final as
select b.orderdate,
b.promo_type,
b.payment_type,
sum(b.Payment_Amt) as Payment_amt,
sum(a.Sales_Amt) as Sales_amt
from sales a
left join payment b
on a.orderdate=b.orderdate
group by 1,2,3
;
quit;

PaigeMiller
Diamond | Level 26

Simple debugging of your code (which you should do yourself from now on): I modify your PROC SQL so we can see what the merge is doing

 

proc sql;
    create table final as
    select b.orderdate,
        b.promo_type,
        b.payment_type,
        b.payment_amt,
        a.sales_amt
    from sales a
    left join payment b on a.orderdate=b.orderdate ;
quit;

 

This produces the following table:

 

PaigeMiller_0-1656677070035.png

 

So when Payment_type is cash, there are two records and the sum of the sales amount would then be doubled

 

Which brings up the question ... why do you want to do this merge in the first place? Why don't you compute total sales from the sales data and total payments from the payment data?

--
Paige Miller
_el_doredo
Quartz | Level 8
Sorry for the last response. Actually requirement is not right in this case..

Thanks for your help

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 779 views
  • 0 likes
  • 2 in conversation