How can I do the vertical sum in the SAS programs, as below
Does it do by proc means?
Thanks!
id | condition | 2007 | 2008 | 2009 | 2010 |
---|---|---|---|---|---|
1 | A | 0 | 0 | 1 | 1 |
1 | B | 0 | 1 | 1 | 2 |
1 | C | 1 | 1 | 2 | 2 |
sum | 1 | 2 | 4 | 5 | |
2 | B | 0 | 1 | 2 | 2 |
2 | C | 0 | 2 | 2 | 2 |
sum | 0 | 3 | 4 | 4 |
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;
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
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).
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.
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 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.