Hello,
I a have a dataset as follows:
data have;
input year item $ type $ ;
datalines;
2020 a 1
2020 a 2
2020 a 1
2021 b 1
2021 b 2
2021 a 3
2022 a 1
2022 a 2
2022 a 2
2022 b 3;
run;
Using tabulate procedure as follows, I can get desired results but I wanted to "all" total items sold each year vertically , instead of horizontally. So mainly, how to rotate all row for each year from horizontally to vertically?
proc tabulate data = have;
class year item type;
table year * (item * type all), N='Count type'(pctn< type all> = "Pctn Type" ) /printmiss misstext= '0' ;
run;
Here is desired output:
Count type | Pctn Type | All | |||
year | item | type |
2 |
66.67 |
3 |
2020 | a | 1 | |||
2 | 1 | 33.33 | |||
3 | 0 | 0 | |||
b | 1 | 0 | 0 | ||
2 | 0 | 0 | |||
3 | 0 | 0 | |||
2021 | item | type |
0 |
0 |
3 |
a | 1 | ||||
2 | 0 | 0 | |||
3 | 1 | 100 | |||
b | 1 | 1 | 50 | ||
2 | 1 | 50 | |||
3 | 0 | 0 | |||
2022 | item | type |
1 |
33.33 |
4 |
a | 1 | ||||
2 | 2 | 66.67 | |||
3 | 0 | 0 | |||
b | 1 | 0 | 0 | ||
2 | 0 | 0 | |||
3 | 1 | 100 |
Tabulate isn't going to do a "merged row cells" that way.
About the only way I can think of that to make one column with merged count would be to summarize the data in a data set and use the data step Report Writing Interface build the cells with the row spanning you request.
OK, i understand.
Thank you .
You could add the information at the bottom of the table.
proc tabulate data = have;
class year item type;
keylabel n=' ';
table
year * (item * type) year*all,
N='Count type'(pctn< type all> = "Pctn Type" )
/printmiss misstext= '0' ;
run;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.