在某些数据清理过程中,需要比较不同行之间的数据。例如,如果各行具有相同的countryID和subjectID,则保持最高温度:
CountryID SubjectID Temperature 1001 501 36 1001 501 38 1001 510 37 1013 501 36 1013 501 39 1095 532 36
在这种情况下,我将使用以下lag()
功能。
proc sort table; by CountryID SubjectID descending Temperature; run; data table_laged; set table; CountryID_lag = lag(CountryID); SubjectID_lag = lag(SubjectID); Temperature_lag = lag(Temperature); if CountryID = CountryID_lag and SubjectID = SubjectID_lag then do; if Temperature上面的代码可能有效。
但是我仍然想知道是否有更好的方法来解决此类问题?
1> Alexey Sigid..:我认为您使任务复杂化。您可以使用
proc sql
和max
运行:proc sql noprint; create table table_laged as select CountryID,SubjectID,max(Temperature) from table group by CountryID,SubjectID; quit;