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;
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: