BookmarkSubscribeRSS Feed
sascode
Quartz | Level 8

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
4 REPLIES 4
ballardw
Super User

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.

sascode
Quartz | Level 8

OK, i understand.

Thank you .

Patrick
Opal | Level 21

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;

Patrick_0-1685152693851.png

 

sascode
Quartz | Level 8
Yes, it is true, however, i would like to have it vertically .
Thank you for your time.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 516 views
  • 0 likes
  • 3 in conversation