@tonybesas:
Something like below should work - under the assumption that the order of WORD values in TWO matches that of the like-named variables in ONE:
data one ;
input file $ baby back ball bear beat begin call ;
lines ;
text1 3 4 0 1 0 1 0
text2 2 0 0 3 3 1 2
text3 0 0 0 1 0 5 1
text4 1 1 2 1 1 4 1
;
run ;
data two ;
input word $ pole $ ;
lines ;
baby f3neg
back f1pos
ball f1pos
bear f2pos
beat f2neg
begin f2neg
call f3pos
;
run ;
data want ;
array x [2,7] _temporary_ ;
if _n_ = 1 then do _i_ = 1 by 1 until (z) ;
set two (keep = pole) end = z ;
x[1,_i_] = input (char (pole, 2), 1.) ;
x[2,_i_] = choosen (findc ("np", char (pole,3)), -1, 1) ;
end ;
set one ;
array v baby--call ;
array F [3] ;
do over v ;
_n_ = x[1,_i_] ;
f[_n_] = sum (f[_n_], v * x[2,_i_]) ;
end ;
run ;
Or, alternatively, the array X can be replaced by a hash table, which has the advantage of not making the assumption mentioned above, as the attributes for each variable (which F and which sign) are searched by the variable name in the table X:
data want (drop = _:) ;
if _n_ = 1 then do ;
dcl hash x () ;
x.definekey ("_w") ;
x.definedata ("_n_", "_iorc_") ;
x.definedone () ;
do _n_ = 1 by 1 until (z) ;
set two (rename=word=_w) end = z ;
x.add (key:_w, data:input(char(pole,2),1.), data:choosen(findc("np",char (pole,3)),-1,1)) ;
end ;
end ;
set one ;
array v baby--call ;
array F [3] ;
do over v ;
x.find (key:vname(v)) ;
f[_n_] = sum (f[_n_], v * _iorc_) ;
end ;
run ;
Kind regards
Paul D.
... View more