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

How can I do the vertical sum in the SAS programs, as below

Does it do by proc means?

Thanks!

idcondition200720082009

2010

1A0011
1B0112
1C1122
sum1245
2B0122
2C0222
sum0344
1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

And to cover the reporting bases a Proc tabulate approach

proc tabulate data=have;

     class id;

     class condition;

     var  y2007 y2008 y2008 y2009 ;

     table id*(condition All='Sum'),

             (y2007 y2008 y2008 y2009) * (sum=''*f=best5.)

    ;

run;

View solution in original post

4 REPLIES 4
naveen20jan
Obsidian | Level 7

Hi Zino  ,

proc mean will work perfectly fine in this case .

proc means data = have ;

var  2007 2008 2008 2009 ;

class id ;

run;

Hope this will help you

RW9
Diamond | Level 26 RW9
Diamond | Level 26

To note, 2007, 2008 etc. are not valid SAS variable names.  Also I would suggest you don't use data as column names, use something abstract so you can use array processing, and labels if you need more description:

ID          CONDITION          COL1          COL2

"ID"        "Condition"            "2007"          "2008"

Personally, the data you are dealing with, I would consider another approach.  Store your data as:

ID     CONDITION          YEAR          VALUE

1       "A"                        2007            1

1       "A"                        2007             2

...

This way you can do all of your summary functions on by groups and let SAS work out what the groups are.  For instance if you have 15 years, do you want to specify each year as a column?  (Ok, you can do it it with lists and positioning)  And then if you need it transposed do that before your proc report.  I.e. separate the work data (that which makes your life easier) with the output data (that which makes the recipients life easier).

Astounding
PROC Star

PROC PRINT has very simple options (such as SUM and SUMBY statements) that allow you to get totals and subtotals of numeric variables.

That's if you are looking to get a report, rather than a data set as your output.

Good luck.

ballardw
Super User

And to cover the reporting bases a Proc tabulate approach

proc tabulate data=have;

     class id;

     class condition;

     var  y2007 y2008 y2008 y2009 ;

     table id*(condition All='Sum'),

             (y2007 y2008 y2008 y2009) * (sum=''*f=best5.)

    ;

run;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 4 replies
  • 1862 views
  • 2 likes
  • 5 in conversation