BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
MarkusAurelius
Calcite | Level 5

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

 

1 ACCEPTED SOLUTION

Accepted Solutions
Cynthia_sas
SAS Super FREQ

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

3 REPLIES 3
ballardw
Super User

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.

Cynthia_sas
SAS Super FREQ

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

MarkusAurelius
Calcite | Level 5
Thanks Cynthia

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

What is Bayesian Analysis?

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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