Help using Base SAS procedures

vertical sum

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 7
Accepted Solution

vertical sum

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

Accepted Solutions
Solution
‎05-11-2015 12:13 PM
Super User
Posts: 10,500

Re: vertical sum

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


All Replies
Contributor
Posts: 30

Re: vertical sum

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

Super User
Super User
Posts: 7,401

Re: vertical sum

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).

Super User
Posts: 5,083

Re: vertical sum

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.

Solution
‎05-11-2015 12:13 PM
Super User
Posts: 10,500

Re: vertical sum

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;

☑ This topic is SOLVED.

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

Discussion stats
  • 4 replies
  • 314 views
  • 2 likes
  • 5 in conversation