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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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