BookmarkSubscribeRSS Feed
jollygood18
Calcite | Level 5

Hello,

I am currently working on a long-form data set looking to  to get an overall mean of variable as well its standard deviation between and within observations.

For example my data is set up like this.

ID  Visit_Number           Variable

1          1                          3.3

1          2                          5.2

1          3                          6.3

1          4                          2.3

2          1                          8.9

2          2                          5.8

2          3                          6.2

2          4                          3.4

I need three numbers. 1. an overall mean for variable. 2. The standard deviation for variable between observations.  3. The standard deviation for variable within observations.

I am trying to use;

proc means data=data

class ID

var Variable

run;

This gives me a mean and standard deviation for each person but I cannot get an overall st dev between and within observations. I am trying to see if there is greater spread in my variable of interest between observations or within. Any help would be greatly appreciated!

3 REPLIES 3
Ksharp
Super User

What do you mean by The standard deviation  between observations.  The standard deviation  within observations. ?

jollygood18
Calcite | Level 5

I will try to clarify. I am working on classifying a variable on my data-set that is in the form above. So each person in our study has 4 measures of a variable with about 200 people, so a total of 800 observations.

By standard deviation between observations: I mean a number that represents the average standard deviation for variable within each person(just looking within each ID)

My statistics background is not strong so I am not sure if I can just use a class statement ID to get standard deviation of variable for each person and then average those standard devs across entire data-set


By standard deviations between observations: I want to compare our variable of interest between ID(different people). To see how each ID's variable mean and standard deviation compare with another ID.


We want to see if there is more spread within each women(high variation from visit to visit) or more spread between women(high variation from women to women)


Hope this helps.

Ksharp
Super User

OK. That make some sense .

data have;
input ID  Visit_Number           Variable ;
cards;
1          1                          3.3
1          2                          5.2
1          3                          6.3
1          4                          2.3
2          1                          8.9
2          2                          5.8
2          3                          6.2
2          4                          3.4
;
run;
proc sql;
create table a as
 select mean(Variable) as overall_mean from have;

create table b as 
 select id,std(Variable) as with_in_std 
  from have
   group by id;

create table c as
 select mean(with_in_std) as between_std
  from b;
quit;


Xia Keshan

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
  • 3 replies
  • 4107 views
  • 0 likes
  • 2 in conversation