Help using Base SAS procedures

Proc Tabulate Append 2 Tables

Accepted Solution Solved
Reply
New Contributor
Posts: 3
Accepted Solution

Proc Tabulate Append 2 Tables

Hi SAS community,

 

I would like to do a PROC TABULATE that appends 2 different proc tabs into one.  I have a frequency count proc tab and then a sum proc tab.  The frequency of observation has no var as there is no statistic to calculate.  I would like a table like this..

 

SAS EG,
 

Capture.PNG

 


Accepted Solutions
Solution
2 weeks ago
SAS Super FREQ
Posts: 8,743

Re: Proc Tabulate Append 2 Tables

[ Edited ]

Hi:

  (sorry, I cross posted this with your longer explanation) -- tabulate will only "do" one table at a time. So if you have 2 different datasets, you will need to generate 2 separate tables, unless there is some way for you to combine or restructure the data into one table. Or, you could produce one SASREPORT output, with the 2 tables side by side. I believe in EG, you would make each table in your project and then in the project, do File --> New --> Report to rearrange the 2 tables to be side by side.)

 

  As others have pointed out, without sample data, it is hard to comment. However, what you describe is very basic TABULATE syntax. You indicated that you were using EG and so the point and click tasks to get this accomplished in the Task/Wizard  are too lengthy to post. The amount of code needed is fairly trivial. Using SASHELP.PRDSALE, which is some very fake data, with the same number of obs for every group, I've nearly duplicated the concept of your table, like this:

tab_tables.png

 

I color coded the TABLE statement above, so you could see which part of the code is producing which part of hte output.

 

Here's the full code:

proc tabulate data=sashelp.prdsale;
 title 'TABULATE tables';
  class country region prodtype product;
  var actual;
  table country*region,
        n='Freq'*product sum='Sum'*actual=' '*prodtype;
run;

Hope this helps.

 

cynthia

View solution in original post


All Replies
Super User
Posts: 10,516

Re: Proc Tabulate Append 2 Tables

[ Edited ]

AT least provide some variable names and what role. For example are your "Primary" and "Secondary" separate variables or levels of one variable? Same with the "TV" "CD" "DVD" "Radio".

In the hours worked what varaible is summed? and are the "Admin" "Travel" etc one or four variables?

Since you say "append" it seems you may have existing tabulate code to generate two separate tables. If so post the code for those.

 

Best would be to provide a few rows of data clarify such things. Best is a data step with at least 2 cities and 2 "Peeps" so we could test data. Dummy values are fine to protect the innocent but the hours should not all be the same. Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.

You need not post the whole data set just enough rows to test the logic.

 

 

Is there a recquirement for a total row for each City? It also appears that you might be indicating an overall total at the top.

 

I don't see any serious problem with such a report though some display formats such as RTF documents may have issues with page width depending on your settings.

Solution
2 weeks ago
SAS Super FREQ
Posts: 8,743

Re: Proc Tabulate Append 2 Tables

[ Edited ]

Hi:

  (sorry, I cross posted this with your longer explanation) -- tabulate will only "do" one table at a time. So if you have 2 different datasets, you will need to generate 2 separate tables, unless there is some way for you to combine or restructure the data into one table. Or, you could produce one SASREPORT output, with the 2 tables side by side. I believe in EG, you would make each table in your project and then in the project, do File --> New --> Report to rearrange the 2 tables to be side by side.)

 

  As others have pointed out, without sample data, it is hard to comment. However, what you describe is very basic TABULATE syntax. You indicated that you were using EG and so the point and click tasks to get this accomplished in the Task/Wizard  are too lengthy to post. The amount of code needed is fairly trivial. Using SASHELP.PRDSALE, which is some very fake data, with the same number of obs for every group, I've nearly duplicated the concept of your table, like this:

tab_tables.png

 

I color coded the TABLE statement above, so you could see which part of the code is producing which part of hte output.

 

Here's the full code:

proc tabulate data=sashelp.prdsale;
 title 'TABULATE tables';
  class country region prodtype product;
  var actual;
  table country*region,
        n='Freq'*product sum='Sum'*actual=' '*prodtype;
run;

Hope this helps.

 

cynthia

New Contributor
Posts: 3

Re: Proc Tabulate Append 2 Tables

Thanks Cynthia
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 147 views
  • 1 like
  • 3 in conversation