BookmarkSubscribeRSS Feed
Viktoreli
Obsidian | Level 7

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)

5 REPLIES 5
SuryaKiran
Meteorite | Level 14

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. 

 

Thanks,
Suryakiran
Viktoreli
Obsidian | Level 7

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)

 

 

 

ChrisHemedinger
Community Manager

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;
Check out SAS Innovate on-demand content! Watch the main stage sessions, keynotes, and over 20 technical breakout sessions!
Viktoreli
Obsidian | Level 7
Thank you very, much I am incredibly gratefull!
VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

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

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 5 replies
  • 583 views
  • 3 likes
  • 4 in conversation