Solved
Contributor
Posts: 21

Hello I have two data sets.

One data set is

par       EST    t

Inter     123     7

HW      212    16

WW      78      5

My second data set is

FAMINC   HW   WW

122          143   897

432          987   645

212          789   656

132          123   112

In second data set i need a new variable p = value of inter from table1(which is 123) + value of HW from table1(which is 212) * value of column HW from table2 + value of WW from table1(which is 78) * value of column HW from table2.

So the output should be

P

123 +  212(143) +78(897) = 100305

123 +  212(987) +78(645) =

123 +  212(789) +78(656) =

123 +  212(123) +78(112) =

please any help would be nice......

Accepted Solutions
Solution
‎05-06-2017 06:55 AM
Posts: 1,137

Alternatively with proc tranpose and merge step to be more robust

``````data have1;
input par \$      EST    t;
cards;
Inter     123     7
HW      212    16
WW      78      5
;

data have2;
input FAMINC   HW   WW  ;
cards;
122          143   897
432          987   645
212          789   656
132          123   112
;

proc transpose data=have1 out=trans;
var est;
run;

data have3;
merge have2 trans;
retain col1_ col2_ col3_;
array t(3) col1 col2 col3;
array t2(3) col1_ col2_ col3_;
do i = 1 to 3;
if t(i) ne . then t2(i)=t(i);
end;
j=1;
p=t2(j)+hw*t2(j+1)+ ww*t2(j+2);
run;``````
Thanks,
Jag

All Replies
Posts: 1,137

``````data have1;
input par \$      EST    t;
cards;
Inter     123     7
HW      212    16
WW      78      5
;

data have2;
input FAMINC   HW   WW  ;
cards;
122          143   897
432          987   645
212          789   656
132          123   112
;

data have3;
set have2 ;
array t(3) (123 212 78);
i=1;
p=t(i)+hw*t(i+1)+ ww*t(i+2);
run;``````
Thanks,
Jag
Solution
‎05-06-2017 06:55 AM
Posts: 1,137

Alternatively with proc tranpose and merge step to be more robust

``````data have1;
input par \$      EST    t;
cards;
Inter     123     7
HW      212    16
WW      78      5
;

data have2;
input FAMINC   HW   WW  ;
cards;
122          143   897
432          987   645
212          789   656
132          123   112
;

proc transpose data=have1 out=trans;
var est;
run;

data have3;
merge have2 trans;
retain col1_ col2_ col3_;
array t(3) col1 col2 col3;
array t2(3) col1_ col2_ col3_;
do i = 1 to 3;
if t(i) ne . then t2(i)=t(i);
end;
j=1;
p=t2(j)+hw*t2(j+1)+ ww*t2(j+2);
run;``````
Thanks,
Jag
Super User
Posts: 9,854

``````data have1;
input par \$      EST    t;
cards;
Inter     123     7
HW      212    16
WW      78      5
;

data have2;
input FAMINC   HW   WW  ;
cards;
122          143   897
432          987   645
212          789   656
132          123   112
;

proc transpose data=have1 out=trans;
var est;
id par;
run;
data want;
set have2;
if _n_=1 then set trans(rename=(hw=_hw ww=_ww));
want=inter+_hw*hw+_ww*ww;
run;
``````
Super User
Posts: 18,997

It looks like you're scoring a model, can you use PROC SCORE?

It looks to be a linear model.

Or could you use the SCORE option/statement within the PROC you used? I suspect those solutions are easier than this.

http://blogs.sas.com/content/iml/2014/02/19/scoring-a-regression-model-in-sas.html

Contributor
Posts: 21

I tried PROC SCORE but it's not working.

I think on my other post before a week you suggested me PRCO SCORE. On my other code PROC SCORE is working fine. But for this code PROC SCORE is not wokring.

☑ This topic is solved.