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,
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:
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
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.
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:
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
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Select SAS Training centers are offering in-person courses. View upcoming courses for: