Help using Base SAS procedures

Weighting variables in proc tabulate

Reply
N/A
Posts: 0

Weighting variables in proc tabulate

Good morning,

I want to use the proc tabulate procedure and I want to assing different weights to different variables in the same procedure. If I use the option

weight variable_name;

at the end of the procedure, all variables of the procedure are weighting by the variable variable_name, but I want only some of them to be weighted.

Is it possible? Or I have to do it in several steps.

Thank you.
Super User
Posts: 10,044

Re: Weighting variables in proc tabulate

Posted in reply to deleted_user
Hi . I think you are right. But there is a better choice to use proc report.just need some more codes if you'd like to. And Cynthia@sas.com can do it very well.What you need to do is to post your original code. :-)
N/A
Posts: 0

Re: Weighting variables in proc tabulate

Hi,

My code is:

proc tabulate data=prueba;
var var1 peso var2 funcion;
class ambito estado tiempo/ preloadfmt;
table all*(n
funcion*sum
peso*sum
var2*mean
var1*mean)
ambito=''*(N
peso*sum
var2*mean
var1*mean),
all estado=''*(all tiempo='')
/ printmiss misstext='-';
weight peso;
run;

The variables which I want to be weighted are var1 and var2.
The variable peso is the variable I want to use for weighting.
I do not want to be weighted either peso variable or N variable or funcion variable.

But if I write the code as before, all variables are weighted. How can I write it?

Thanks
SAS Super FREQ
Posts: 8,868

Re: Weighting variables in proc tabulate

Posted in reply to deleted_user
Hi:
Since I was a Literature major, I don't dabble in statistics and weights much. However, I do know how to read the documentation.

A WEIGHT statement will apply to ALL the analysis variables, as described here:
http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/viewer.htm#/documentation/cdl/en...

However, PROC TABULATE allows you to have multiple CLASS statements and multiple VAR statements just for the purpose of specifying different options for different category and analysis variables.
http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/viewer.htm#/documentation/cdl/en...

As it says in the documentation on the VAR statement:
Tip: Use the WEIGHT option in multiple VAR statements to specify different weights for the analysis variables.

The general syntax for having multiple VAR and CLASS statements is:
[pre]
VAR peso / weight=xxxxx;
VAR var1 var2 funcion;
CLASS ambito / preloadfmt;
CLASS estado tiempo / style={background=pink};
[/pre]

cynthia
N/A
Posts: 0

Re: Weighting variables in proc tabulate

Posted in reply to Cynthia_sas
Ok. Thanks, that was what I wanted.

I didn't know how to write multiple VAR statements with differents weights.
Super User
Posts: 10,044

Re: Weighting variables in proc tabulate

Posted in reply to deleted_user
Hi. Your proc tabulate is a little complicated.the following code is just an example,you can use proc report to get more about weight variable.


[pre]
define estado /group;
define ambito /group;
define peso /analysis sum;
define var1 /analysis mean;
define var2 /analysis mean;
break after ambito /summarize;
compute var1;
s_var1=peso.sum*var1.mean;
if _break_=' ' then sum_var1+s_var1;
endcomp;
compute var2;
s_var2=peso.sum*var1.mean;
if _break_=' ' then sum_var2+s_var2;
endcomp;
compute after ambito;
var1.mean=sum_var1/peso.sum;
var2.mean=sum_var2/peso.sum;
endcomp;

[/pre]


it is Untest.
Ask a Question
Discussion stats
  • 5 replies
  • 513 views
  • 0 likes
  • 3 in conversation