Rim weighting in sas

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 12
Accepted Solution

Rim weighting in sas

[ Edited ]

Hi I have a sas data set of FMCG sector with below demographics  

 

Males 45%

Females 55%

 

Age group 18-35  48%

Age group 35-55+ 52%

 

 

 

now the client wants me to calculate weighting factor for every respondent in the data so as to get below demographics percentage

 

Males 50%

Females 50%

 

Age group 18-35  30%

Age group 35-55+ 70%

 

If i calculate this through rim weights a respondents whould have weight factors as per below is

 

male - age 18-35 ---> 0.69444

male - age 35-35+ ---> 1.495

female - age 18-35 ---> 0.568

female - age 35-35+ ---> 1.223

 

Can i calculate such weight factors through SAS, where i can supply the expected precentages and get weight factors?


Accepted Solutions
Solution
‎08-29-2017 01:46 AM
Super Contributor
Posts: 320

Re: Rim weighting in sas

You can trivially calculate them by doing a PROC FREQ, then merge them back to the main table along with the targets.

 

 

data have;
  call streaminit(7);
  do _n_=1 to 2000;
     if rand('uniform')<=.48 then age='18-35';    
     else age='35+';
     if rand('uniform')<=.45 then sex='M  '; 
     else sex='F';
     output;
  end;
run;

proc freq data=have;
  tables age*sex/out=age_sex_totals;
run;

data targets;
length age $5 sex $1;
input age $ sex $ target;
datalines;
18-35 F .15
18-35 M .15
35+   F .35
35+   M .35
;;;;
run;

proc sort data=targets;
by age sex;
run;

data want_wts;
  merge age_sex_totals targets;
  by age sex;
  weight = 100*target/percent;
run;

proc sort data=have;
  by age sex;
run;

data want;
  merge have want_wts;
  by age sex;
run;

proc freq data=want;
  weight weight;
  tables age*sex;
run;

 

For more complicated cases, there are macros online (RAKINGE is the one I typically use).

View solution in original post


All Replies
Solution
‎08-29-2017 01:46 AM
Super Contributor
Posts: 320

Re: Rim weighting in sas

You can trivially calculate them by doing a PROC FREQ, then merge them back to the main table along with the targets.

 

 

data have;
  call streaminit(7);
  do _n_=1 to 2000;
     if rand('uniform')<=.48 then age='18-35';    
     else age='35+';
     if rand('uniform')<=.45 then sex='M  '; 
     else sex='F';
     output;
  end;
run;

proc freq data=have;
  tables age*sex/out=age_sex_totals;
run;

data targets;
length age $5 sex $1;
input age $ sex $ target;
datalines;
18-35 F .15
18-35 M .15
35+   F .35
35+   M .35
;;;;
run;

proc sort data=targets;
by age sex;
run;

data want_wts;
  merge age_sex_totals targets;
  by age sex;
  weight = 100*target/percent;
run;

proc sort data=have;
  by age sex;
run;

data want;
  merge have want_wts;
  by age sex;
run;

proc freq data=want;
  weight weight;
  tables age*sex;
run;

 

For more complicated cases, there are macros online (RAKINGE is the one I typically use).

Occasional Contributor
Posts: 12

Re: Rim weighting in sas

Posted in reply to snoopy369

Hi Snoopy

 

RAKINGE is the macro i am interested but i cant understand where to enter the target weights and update the macro to run for age and gender .....can you please share a working e.g. for the same on a random data set similar to what i have explained earlier.

 

your guidance would be really helpful.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 339 views
  • 0 likes
  • 2 in conversation