BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
chintanpatel
Calcite | Level 5

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......

1 ACCEPTED SOLUTION

Accepted Solutions
Jagadishkatam
Amethyst | Level 16

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

View solution in original post

5 REPLIES 5
Jagadishkatam
Amethyst | Level 16

Please try

 

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
Jagadishkatam
Amethyst | Level 16

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
Ksharp
Super User
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;
Reeza
Super User

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

 

 

chintanpatel
Calcite | Level 5

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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 955 views
  • 0 likes
  • 4 in conversation