sas >> Difference between VAR,ID,BY,CLASS

by Raj » Sun, 01 Aug 2010 16:17:52 GMT

Hi,

Can somebody explain where we use VAR,ID,BY,CLASS and what is the
difference between each one with an example.

Thanks for the help.

Regards,
Raj


sas >> Difference between VAR,ID,BY,CLASS

by Bob » Sun, 01 Aug 2010 20:12:04 GMT


Here is a good article from SAS on the PROC SUMMARY. That is the
procedure where those are primarily used.

http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/viewer.htm #/documentation/cdl/en/proc/61895/HTML/default/a002473735.htm

CLASS and BY are used to tell SAS what variable(s) to use when
summarizing the dataset. (The difference being BY variables must be
presorted). ID is used to tell SAS, 'don't summarize by this variable,
but display the first value for a given BY variable combination'. VAR
is used for numeric variables you would like a calculation performed
on (usually summation).

Example:
proc summary data=[input dataset] nway missing;
class [var1] [var2];
id [var3];
var [var4];
output out=[output dataset] sum=;
run;

This summarizes the input dataset by var1 and var2, displays var3, and
subtotals var4 for each var1/var2 combination. Make sense?








sas >> Difference between VAR,ID,BY,CLASS

by Arthur Tabachneck » Sun, 01 Aug 2010 21:28:14 GMT

Raj,

I'd expand on Bob's response and make a couple of minor corrections.

First, the concepts aren't limited to proc summary, but are general to
many SAS procs. In fact, the documentation provides a lot more detail
in its section on proc summary's relative .. proc means (see, e.g.:
http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/viewer.htm #/documentation/cdl/en/proc/61895/HTML/default/a000146728.htm

or, in short form: http://xrl.us/bhuwpz )

In some procs, 'table' or 'model' might be the keyword used rather
than 'var'.

The 'by' statement gives you a way to mix orders so that all don't
have to be ascending or descending, lets you use the #byval variable
and, I believe, requires less resources (thus can handle more complex
designs before confronting memory problems).

The ID statement gives you a way to include additional, non-summarized
values. The documentation provides more detail than I could provide
here but, rather than the first value encountered in a by or class
group combination, it can either be the minimum or maximum value
within a by or class group combination.

HTH,
Art
---------------

> lass [var1] [var2];> > d [var3>;
> ar [va>4];
> utput out=[output dataset]>sum=;
>
> This summarizes the input dataset by var1 and var2, displays var>, and
> subtotals var4 for each var1/var2 combination. Make >en>e?
>
> On Aug 1, 3:17lt;m, Raj >ro>e:> >> >
>
>>> >i>
>
> > Can somebody explain where we use VAR,ID,BY,CLASS and what >s>the
> > difference between each one with an ex>mp>e>
>
> > Thanks for the>he>p>
>
> > Re>a>ds,
> > Raj- Hide quoted >ex> -
>
> - Show quoted text -



Similar Threads

1. Difference between VAR,ID,BY,CLASS

2. Difference Between ID and Class Statements

Hello All.

I have read the manuals and other sources of information.  What is the
difference between the ID and Class statements of PROC Summary?
Thanks In Advance=20

3. create ID var

4. how to get Mean by two variables, ID and the other var,

Hi SASLs,

My data has multi-measurement by drug for each ID. I want to calculate the =
mean for the same drug for each ID when each ID has multi-values for each d=
rug. When I do the below code, sometimes for the same ID, the mean is combi=
ned both difference drug. Can someone help me on figure out the error of my=
 code? Thanks much!

my data is:
id=A0 drug var1
1=A0=A0 a=A0=A0=A0=A0 0.3
1=A0=A0 a=A0=A0=A0=A0 0.4
1=A0=A0 b=A0=A0=A0=A0 1.1
1=A0=A0 b=A0=A0=A0=A0 0.8
1=A0=A0 b=A0=A0=A0=A0 0.7

I want:
id=A0 drug var1
=0A1=A0=A0 a=A0=A0=A0 =A0=A0 0.3
=0A1=A0=A0 a=A0=A0=A0 =A0=A0 0.4
1=A0=A0 mean=A0 0.35
=0A1=A0=A0 b=A0=A0=A0=A0=A0=A0=A0 1.1
=0A1=A0=A0 b=A0=A0=A0=A0=A0 =A0 0.8
=0A1=A0=A0 b=A0=A0=A0=A0=A0=A0=A0 0.7
1=A0=A0 mean=A0 0.87

My code:=20
data want (drop=3Dtot );
do until(last.id);
set want;
by id drug;
tot=3Dsum(0, tot, var1);
N=3Dsum(n,n(var1));
output;
end;
var1=3Dtot/n;
drug=3D'mean_var1';
output;
title 'calculate mean of var1 by patient and by drug';
run;

The results of above code are:=20
id=A0 drug var1
=0A=0A1=A0=A0 a=A0=A0=A0 =A0=A0 0.3
=0A=0A1=A0=A0 a=A0=A0=A0 =A0=A0 0.4
=0A1=A0=A0 b=A0=A0=A0=A0=A0=A0=A0 1.1
=0A=0A1=A0=A0 b=A0=A0=A0=A0=A0 =A0 0.8
=0A=0A1=A0=A0 b=A0=A0=A0=A0=A0=A0=A0 0.7
=0A1=A0=A0 mean=A0=20

It combine the a and b for the same ID.=20

Jane


--- On Thu, 5/14/09, Data _null_; < XXXX@XXXXX.COM > wrote:

From: Data _null_; < XXXX@XXXXX.COM >
Subject: Re: what is the correct 'Mean' statement in SAS for calulcating me=
an  by ID with multiple measurement/var
To: "jn mao" < XXXX@XXXXX.COM >
Cc:  XXXX@XXXXX.COM 
Date: Thursday, May 14, 2009, 11:58 AM

You can't use the MEAN function in a vertical fashion as you are
trying to do. You must sum then get mean.

I would not use data step to summarize data.=A0 The mistake you made is
a good example of the reason why.

data wk;
=A0=A0=A0input id var1;
=A0=A0=A0cards;
1=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=A0=A00.551724138
1=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=A0=A00.333333333
1=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=A0=A00.12345679
;;;;
=A0=A0=A0run;
proc means; * check;
=A0=A0=A0var var1;
=A0=A0=A0run;
data want;
=A0=A0=A0do until(last.id);
=A0 =A0 =A0 set wk;
=A0 =A0 =A0 by id;
=A0 =A0 =A0 sum=3Dsum(sum,var1);
=A0 =A0 =A0 N=A0 =3Dsum(n,n(var1));
=A0 =A0 =A0 output;
=A0 =A0 =A0 end;
=A0=A0=A0var1=3Dsum/n;
=A0=A0=A0category=3D'mean_var1';
=A0=A0=A0output;
=A0=A0=A0stop;
=A0=A0=A0title 'calculate mean of var1 by ID';
=A0=A0=A0run;
proc print;
=A0=A0=A0run;

On 5/14/09, jn mao < XXXX@XXXXX.COM > wrote:
> Hello SAS-Ls,
>
> I need to calculate the mean by ID when each ID has multiple measurement =
on Var1, below is my code. But when I convert it excel file, by manually re=
-calculate the mean for each ID, the results are always not the same, can a=
nyone help me figure it out? Thanks much.
>
> Here is SAS code:
>
> data want (drop=3Davgra);
> do until(last.id);
> set wk;
> by id;
> avgra=3Dmean(avgra, var1);
> output;
> end;
> var1=3Davgra;
> category=3D'mean_var1';
> output;
> title 'calculate mean of var1 by ID';
> run;
>
> For eg. with above code, for ID1 I got,
> id=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 var1
> 1=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=A0=A00.551724138
> 1=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=A0=A00.333333333
> 1=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=A0=A00.12345679
> mean_sas=A0 =A0 =A0 =A0 0.282992763
>
> But in Excel/manual, mean=3D0.33
>
> Why?, does the Mean statement wrong? Thanks,
>
> Jane
>
>
>
>
>
>
>
=0A=0A=0A

5. restore the original id var after second transpose ?

6. difference between CLASS and BY statement

Hi all!
I've always wondered what is the difference between CLASS and BY
statements in a MEANS procedure or in a SUMMARY procedure. And why does
BY statement requires the variable to be sorted and CLASS does not?

Thanks!

7. What is the difference between VAR A1 - A4 and VAR A1 -- A4 ?

8. NLMIXED:Intra class correlation versus Inter class correlation

Hello,

Following M. Zack remark, the answer that I got here is for the intra class correlation and not for  the inter class correlation,sorry about that

---------------------------------------Previous message-------------------------------------------------

I  have asked the below question weeks ago, and I have addressed the same questions to our fiends Dale and Matthew, but I did not have a response about this, Matthew gave me some ideas which allows me to investigate the problem .

And I have the following answer about my question and I would to have your feedback (this is the intraclass correlation)


Su2 is the amount of variation due to the random effect (random residual)

Se2 is the amount of variation due to the fixed effect (fixed residual)

Su2 + Se2 is the total variation

rho = Su2/(Su2 + Se2) the fraction of residual variability that can be ascribed to level two

Su2 and Se2 can be obtained from the covariance matrix of parameter estimates

in the NLMIXED procedure

And what will be the inter class correlation, big challenge, is not it?



My first  question to the list:

I would like to ask if there is any possibility in SAS, to estimate or to compute, the Inter class correlation estimate, or the fraction of residual variability of the level 2, in NLMIXED when the dependent variable is binary.



Since we got the S2 , the variance of the random effect, but I think it is useful to interpret this quantity as a correlation.



Thank you very much in advance for any suggestion.



Adel









---------------------------------
 Douvrez le nouveau Yahoo! Mail : 1 Go d'espace de stockage pour vos mails, photos et vids !
Crz votre Yahoo! Mail