BookmarkSubscribeRSS Feed
Shradha1
Obsidian | Level 7

I have a transaction dataset with customer number, merchant category, transaction amount, online flag, and domestic/overseas flag.

Merchant category has different observations like Dining, Apparel, Games, Grocery, electronics etc.

Now for each of these merchant categories, I want to get the total amount spent, total number of online transactions, and total number of overseas transaction for each customer. Ex:  For Dining, there will be 3 variables: Total amount spent on dining, total number of online transactions for dining, and total numbe rof overseas dining transactions.

 

So, for 5 different merchant categories, there will be 3 variable each, so total 15 variables in the final dataset, at a customer level.

How do I do this rather than having to write 15 'Case When' statements in proc sql?

 

 

1 REPLY 1
PaigeMiller
Diamond | Level 26

This is a job for PROC SUMMARY

 

proc summary data=have nway;
    class merchant_category;
    var amount num_transactions num_overseas_transactions;
    output out=_stats_ sum=/autoname;
run;
--
Paige Miller

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 1 reply
  • 650 views
  • 1 like
  • 2 in conversation