既然你要求重复情况也多次计算,我改了下_a - _d的计数,所有代码如下:
data certificate ;
input id (certArea1-certArea30) ($) ;
datalines ;
1 32 11 . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2 32 . 23 . . . . . . . . . . . . . . . . . . . . . . . . . . .
3 23 21 32 . . . . . . . . . . . . . . . . . . . . . . . . . . .
4 30 24 25 . . . . . . . . . . . . . . . . . . . . . . . . . . .
;
run ;
data assignment ;
input assign $ (certArea1-certArea30) ($) ;
datalines ;
a 11 . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
b 30 11 . . . . . . . . . . . . . . . . . . . . . . . . . . . .
c 23 . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
d 32 23 . . . . . . . . . . . . . . . . . . . . . . . . . . . .
;
run ;
data certificate ;
set certificate ;
array cert[30] certarea1-certarea30 ;
do i= 1 to 30 ;
if cert= 11 then cert= 3 ;
if cert= 21 then cert= 5 ;
if cert= 23 then cert= 7 ;
if cert= 24 then cert= 11 ;
if cert= 25 then cert= 13 ;
if cert= 30 then cert= 17 ;
if cert= 32 then cert= 19 ;
end ;
run ; * replace raw values with prime numbers ;
data assignment ;
set assignment ;
array cert[30] certarea1-certarea30 ;
do i= 1 to 30 ;
if cert= 11 then cert= 3 ;
if cert= 21 then cert= 5 ;
if cert= 23 then cert= 7 ;
if cert= 24 then cert= 11 ;
if cert= 25 then cert= 13 ;
if cert= 30 then cert= 17 ;
if cert= 32 then cert= 19 ;
end ;
run ; * replace raw values with prime numbers ;
data certificate1 ;
set certificate ;
array certa[30] certarea1 - certarea30 ;
array certa_n[30] certarea_n1 - certarea_n30 ;
do i= 1 to 30 ;
certa_n= input( certa, $8.) ;
end ;
drop i certarea1 - certarea30 ;
run ;* transfer to numeric values ;
data certificate2 ;
set certificate1 ;
array certa_n[30] certarea_n1 - certarea_n30 ;
do i= 1 to 30 ;
if certa_n=. then certa_n= 1 ;
end ;
prod = 1 ;
do j =1 to 30 ;
prod =prod*certa_n[j] ;
end ;
keep id prod ;
run ; * substitude missing values, and create the product value for each id;
data certificate3 ;
set certificate2 ;
if mod(prod,3)=0 then qualifieda= 1 ;
else qualifieda = 0 ;
if mod(prod,17)=0 and mod(prod,3) ne 0 then qualifiedb= 1 ;
else if mod(prod,17)ne 0 and mod(prod,3) =0 then qualifiedb= 1 ;
else if mod(prod,17)=0 and mod(prod,3) =0 then qualifiedb= 2 ;
else qualifiedb = 0 ;
if mod(prod,7)=0 then qualifiedc= 1 ;
else qualifiedc = 0 ;
if mod(prod,19)=0 and mod(prod,7) ne 0 then qualifiedd= 1 ;
else if mod(prod,19)ne 0 and mod(prod,7) =0 then qualifiedd= 1 ;
else if mod(prod,19)=0 and mod(prod,7) =0 then qualifiedd= 2 ;
else qualifiedd = 0 ;
sum= qualifieda+qualifiedb+qualifiedc+qualifiedd ;
_a= qualifieda/sum ;
_b=qualifiedb/sum ;
_c=qualifiedc/sum ;
_d= qualifiedd/sum ;
run ; * determine the contribution values based on the mod function ;
proc means noprint ;
output out= final
sum= ;
var _a _b _c _d ;
run ;