Same frequency distribution
7. July 2007 10:55A frequency distribution is a summary of the data set in which the interval of possible values is divided into subintervals, known as classes. For each class, the number of data values in that class is recorded; this is the frequency of the class. The relative frequency of the class is the frequency of the class divided by the number of values in the data set.
Sometimes we want to compare two populations and we want choose from the second population observations with the frequency distiribution that is similar to the first population.
Example:
data a7; set loans.Ekspr_model_result_200704; if zevet=7; code=km_L_PASIV_month_b*10+kmin_age; run; data a3; set loans.Ekspr_model_result_200704; if zevet=3; code=km_L_PASIV_month_b*10+kmin_age; run;
We want sample from a3 with the frequency distribution according to pasiv and age that the similar to a7.
proc freq DATA=a7;
tables code /out=outkod noprint;
run;
proc freq DATA=a3;
tables code /out=outkod3(rename=(percent=percent3 count=count3)) noprint;
run;
proc sql ;
create table all_res as
seect a.*,count3/new_am as ratio_lacking,
min(count3/new_am) as min_ratio,
from
(
select a.*,
b.percent3,
b.count3,
sum(count3) as counter,
int(sum(count3)*percent/100) as new_am,
percent/percent3 as ratio
from outkod a,
outkod3 b
where a.code=b.code ) a;
quit;
data _null_ ;
set all_res ;
if min_ratio=ratio_lacking;
num_pop=round(count3*100/percent);
call symput('nn',num_pop);
run;
%put &nn;
data all_res1;
set all_res;
new_new=round(&nn*percent/100);
ratio_new_new= (new_new/count3) ;
round_ratio_new=round(ratio_new_new,0.0001);
run;
proc sql noprint;
select round_ratio_new
into :ratio separated BY " "
from all_res1;
quit;
proc surveyselect data=a3 method=srs
rate=(&ratio) out=sample;
strata code;
run;
proc freq data=a7;
tables code;
run;
proc freq data=sample;
tables code;
run;

Email 