BookmarkSubscribeRSS Feed
savagnin_hs
Fluorite | Level 6

先ほどの質問の続きです。(It ’s a continuation.)

 

動物の亜目(suborder)と動物名(animal)を関連づけて、その関連性(relevance)を%で表記したデータベースがあります。

グループ内連番(Q1)とlayer内参照番号(Q2)の後に、計算を行いたいのですが、添付ファイルの計算を行う方法を教えてください。

 

1 REPLY 1
yu_sas
SAS Employee

RETAINステートメントを利用し、値の初期化を防ぐことで可能かと思います。

 

data have;
input suborder_no suborder $ animal $ relevance_animal $ relevance;
informat relevance percent.;
cards;
1 felidae tiger felidae 100%
1 felidae cat felidae 100%
1 felidae tabby_cat cat 90% 
1 felidae american_shorthair_cat tabby_cat 60%
2 canidae wolf canidae 100%
2 canidae dog canidae 100%
2 canidae poodle dog 80%
2 canidae toy_poodle poodle 90%
;

data want;
set have;
by suborder_no;
if first.suborder_no then do;
 animal_no=0; relevance_no=0; relevance_av=1;end;
animal_no+1;
relevance_no+relevance_animal^=lag(relevance_animal);
retain relevance_av 1; format relevance_av percent.;
relevance_av=relevance_av*relevance;
run;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
Discussion stats
  • 1 reply
  • 655 views
  • 0 likes
  • 2 in conversation