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

Hi All,

 

I have data like below

 

Date          B            C        D          E

20141231 193.83  93.04  129.98  96.15
20150102 194.41  93.02  129.95  95.03
20150105 188.34  90.56  129.05  93.5
20150106 184.53  88.63  127.53  92.95
20150107 187.28  90.3    129.51  94.87
20150108 190.27  91.58  131.8   97.06
20150109 187.35  90.42  131.54  95.99
20150112 185.07  89.5    30.87    95.86
20150113 184.93  89.23  131.17  95.01

 

I need to calcute Score = B1*B2+C1*C2+D1*D2+E1*E2

 

How to perform this calculation in SAS, Please advise

1 ACCEPTED SOLUTION

Accepted Solutions
Jagadishkatam
Amethyst | Level 16

Try to get the next record adjacent to the current record and then use the formula.

 

data have;
input Date          B1            C1        D1          E1;
cards;
20141231 193.83  93.04  129.98  96.15
20150102 194.41  93.02  129.95  95.03
20150105 188.34  90.56  129.05  93.5
20150106 184.53  88.63  127.53  92.95
20150107 187.28  90.3    129.51  94.87
20150108 190.27  91.58  131.8   97.06
20150109 187.35  90.42  131.54  95.99
20150112 185.07  89.5    30.87    95.86
20150113 184.93  89.23  131.17  95.01
;

data want;
obss=_n_+1;
set have end=last; if obss<=nobs then set have(keep=b1 c1 d1 e1 rename=(b1=b2 c1=c2 d1=d2 e1=e2)) end=last nobs=nobs point=obss;
if not last then score=sum(B1*B2,C1*C2,D1*D2,E1*E2);
else do;
score=.;
call missing(b2,c2,d2,e2) ;
end;
run;

 

Thanks,
Jag

View solution in original post

5 REPLIES 5
Reeza
Super User
Your formula is correct and will work directly in SAS, by adding a semi colon.

What issue are you having?

Score = B1*B2+C1*C2+D1*D2+E1*E2;
Coa_SAs
Fluorite | Level 6

 

 

 

Reeza,

 

 

I need to multiply first obervation with second and second with third and thrid with fourth.etc.and summing all the reult.

Reeza
Super User
Post the expected output from the data above. Are you looking forward or looking back - does it matter? Looking back is easier, you can use the lag function.

score=B*lag1(b)+c*lag(c) + d1*lag(d) +e*lag1(e);
Jagadishkatam
Amethyst | Level 16

Try to get the next record adjacent to the current record and then use the formula.

 

data have;
input Date          B1            C1        D1          E1;
cards;
20141231 193.83  93.04  129.98  96.15
20150102 194.41  93.02  129.95  95.03
20150105 188.34  90.56  129.05  93.5
20150106 184.53  88.63  127.53  92.95
20150107 187.28  90.3    129.51  94.87
20150108 190.27  91.58  131.8   97.06
20150109 187.35  90.42  131.54  95.99
20150112 185.07  89.5    30.87    95.86
20150113 184.93  89.23  131.17  95.01
;

data want;
obss=_n_+1;
set have end=last; if obss<=nobs then set have(keep=b1 c1 d1 e1 rename=(b1=b2 c1=c2 d1=d2 e1=e2)) end=last nobs=nobs point=obss;
if not last then score=sum(B1*B2,C1*C2,D1*D2,E1*E2);
else do;
score=.;
call missing(b2,c2,d2,e2) ;
end;
run;

 

Thanks,
Jag
Coa_SAs
Fluorite | Level 6

Thanks Reeza and Jagadishkatam, Its working now. Hooray!

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1664 views
  • 2 likes
  • 3 in conversation