我在下面编写了此代码以完成2个任务:
我想知道是否有可能用“ proc sql”过程编写此过程,因为这些天我对sql过程真的很感兴趣。
谢谢大家的帮助!
data test4;
set test3;
if ('01JUL2019'd - EXVISDAT + 1) < OverDueDays then do;
miscrit="";
end;
drop targetdays overduedays;
run;
Run Code Online (Sandbox Code Playgroud)
我设法使用proc sql来更改变量的值。但是不知道如何添加该表中的targetdays和overduedays列的删除代码。
proc sql;
update test05
set miscrit = ""
where ('01JUL2019'd - EXVISDAT + 1) < OverDueDays
;
quit;
Run Code Online (Sandbox Code Playgroud) 在某些数据清理过程中,需要比较不同行之间的数据。例如,如果各行具有相同的countryID和subjectID,则保持最高温度:
CountryID SubjectID Temperature
1001 501 36
1001 501 38
1001 510 37
1013 501 36
1013 501 39
1095 532 36
Run Code Online (Sandbox Code Playgroud)
在这种情况下,我将使用以下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 < Temperature_lag then delete;
end;
drop CountryID_lag SubjectID_lag Temperature_lag;
run;
Run Code Online (Sandbox Code Playgroud)
上面的代码可能有效。
但是我仍然想知道是否有更好的方法来解决此类问题?