Hey!
I wan't to create a table with two variables presented in every cell, one presented in number of observations and the other in mean and standard deviation. I couldn't find a good solution on the web and im somewhat new at SAS and could not get it right by myself.
I want every cell to have the number of observations of variable a(body part) for every variable b(time period) together with the mean and standarddeviation of c for the same variables. If possible I would also like a column and row of totals.
I would be immensly grateful for any help!
Variable a(bodyparts) | Variable b (time periods) P1 | P2 | P... | Total |
a(Head) | number of a (Head) for b (time period 1). Mean and standard deviation of variable c for variable a and b. | a = 80, c = 0.4% (STD=0.04) | ... | C = total number of a for all b, mean of c for a (head) and total b (+STD) |
Legs | a = 78, c = 0.3% (STD=0.03) | ... | ... | ... |
Body part ... | ... | ... | ... | ... |
Total | ... | ... | ... | All a observations, mean of c(STD of d) |
Hello,
Do not give high level requirement information. If you could please provide sample data you have and your required output that work help us in providing your answers quickly.
I hope this helps! I didnt calculate means or standard deviations, I just put an x there instead.
a b c
3 10 1.3095
4 10 0.291
3 25 0.388
4 10 2.91
3 25 0.194
4 25 1.164
4 10 1.121
Variable a(bodyparts) | Time periods… | 10 | 25 | Total |
…
|
|
|
|
|
3 |
| N=1, c mean = 1.3095 (c STD) | N=2, c mean= x (c STD) | N=3, c mean = x (c STD) |
4 |
| N =3, c mean = x (c std) | N =1 c mean = 1.164 ( c std) | N=4, c mean = x (c STD) |
Total |
| N =4, c mean = x (c std) |
| 7 , c mean = x (c STD) |
Here's a start using sample SAS data. It's probably more complicated than you need, but the approach is this:
- Calc the stats and save to data
- Rejoin the stats with the categories they relate to in orginal data
- Use CAT* functions to combine values and text to build what you need for a report.
/* Calc the stats and save */
proc means noprint
data=sashelp.class
mean std;
class sex;
output out=stats ;
run;
/* Combine with stats */
proc sql;
create table classwithstats as
select t1.*,
t2.Age as AvgAge,
t3.Age as StdAge,
t4.Age as N
from sashelp.class t1
left join stats(where=(_TYPE_=1 and _STAT_='MEAN') ) t2
on (t1.Sex=t2.Sex)
left join stats(where=(_TYPE_=1 and _STAT_='STD') ) t3
on (t1.Sex=t3.Sex)
left join stats(where=(_TYPE_=1 and _STAT_='N') ) t4
on (t1.Sex=t4.Sex)
;
quit;
/* Build report text */
data report;
set classwithstats;
length text $ 100;
text = catt('N =',N,' Mean =',avgage,' Std=',stdage);
run;
@SuryaKiran well put. @Viktoreli you did not supply sample data nor what you have tried as SAS code.
Not many of us here get payed to do your assignments, but we are will try to assist you when you provided more than an assignment.
How to create a data-step version of your data
https://communities.sas.com/t5/help/faqpage/faq-category-id/posting#posting
https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat...
How to Add attachments
https://communities.sas.com/t5/Community-Memo/Adding-attachments-to-your-communities-posts/ba-p/4647...
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
https://communities.sas.com/t5/SAS-Communities-Library/Maxims-of-Maximally-Efficient-SAS-Programmers...
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.