Hello Everyone,
I have a dataset below showing variables country, salestype and number of sales.
Country | salestype | sales |
Europe | car | 10 |
Europe | bike | 20 |
Europe | truck | 30 |
Europe | bike | 12 |
Europe | car | 20 |
Europe | bike | 25 |
Europe | truck | 13 |
Europe | truck | 32 |
Europe | bike | 42 |
Europe | car | 52 |
UK | car | 32 |
UK | bike | 45 |
UK | truck | 85 |
UK | car | 25 |
UK | car | 30 |
US | bike | 56 |
US | bike | 16 |
US | car | 13 |
Australia | car | 85 |
Australia | bike | 63 |
Australia | truck | 78 |
Australia | car | 95 |
Australia | bike | 45 |
Australia | truck | 25 |
Asia | car | 62 |
Asia | truck | 35 |
Asia | bike | 15 |
Africa | car | 29 |
Africa | car | 36 |
Africa | bike | 78 |
Africa | bike | 95 |
Africa | car | 45 |
I want the output such that it sums up the sales for each salestype and country and produces a table like below.
car sales | bike sales | truck sales | Total sales | |
Europe | 82 | 99 | 75 | 256 |
UK | 87 | 45 | 85 | 217 |
US | 13 | 72 | 85 | |
Australia | 180 | 108 | 103 | 391 |
Asia | 62 | 15 | 35 | 112 |
Africa | 110 | 173 | 283 | |
Total sales | 534 | 512 | 298 | 1344 |
Could you please guide me to code this. I tried using proc sql but it did not work the way I wanted.
Here's one way to create a report with the right structure. You can always learn more about PROC TABULATE if you want a fancier report:
proc tabulate data=have;
class country salestype;
var sales;
tables country all, (salestype all) * sales=' ' * sum=' ';
run;
Here's one way to create a report with the right structure. You can always learn more about PROC TABULATE if you want a fancier report:
proc tabulate data=have;
class country salestype;
var sales;
tables country all, (salestype all) * sales=' ' * sum=' ';
run;
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.
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.