BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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.
5 REPLIES 5
Ksharp
Super 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. 🙂
deleted_user
Not applicable
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
Cynthia_sas
Diamond | Level 26
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
deleted_user
Not applicable
Ok. Thanks, that was what I wanted.

I didn't know how to write multiple VAR statements with differents weights.
Ksharp
Super 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.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 4267 views
  • 0 likes
  • 3 in conversation