首页 > 解决方案 > 使用与 SAS 中另一列中的值相对应的日期列

问题描述

我想添加到此代码中,以便根据“测量”列中的“日期”列的最后一次测量值除以测量列中记录的最小值,结果形成一个新列。如果“主题”、“类型”和“程序”列匹配,当前的工作代码会添加一个列,该列从“测量”列中的其他测量值中减去初始测量值。先感谢您。

data have;
input Subject Type Date $ 5-12 Procedure $ 15-22 Measurement;
datalines;
500   Initial    15 AUG 2017      Invasive     20 
500   Initial    18 SEPT 2018     Surface      35 
500   Followup   12 SEPT 2018     Invasive     54 
428   Followup    2 JUL 2019      Outer        29 
765   Seventh     3 JUL 2018      Other        13 
500   Followup    6 NOV 2018      Surface      98 
428   Initial     23 FEB 2018     Outer        10 
765   Initial     20 AUG 2019     Other        19 
610   Third       21 AUG 2018     Invasive     66 
610 Initial       27 Mar   2018   Invasive     17 
;
data want (drop=rc _Measurement);
   if _N_ = 1 then do;
      declare hash h (dataset : "have (rename=(Measurement=_Measurement) where=(Type='Initial'))");
      h.definekey ('Subject');
      h.definedata ('_Measurement');
      h.definedone();
   end;

   set have;
   _Measurement=.;

   if Type ne 'Initial' then rc = h.find();
   NewMeasurement = ifn(Measurement=., ., sum (Measurement, -_Measurement));
run;

标签: sortingdateif-statementsasconditional-statements

解决方案


推荐阅读