0
我用下面的數據要計算面積在SAS曲線下面積下:在SAS如何計算曲線
MeasNo X Y ASN
1 10 20 1
2 12 22 1
3 13 21 1
4 14 25 1
5 11 18 1
6 15 21 1
7 13 19 1
8 12 22 1
9 11 18 1
10 10 22 1
1 11 21 2
2 13 24 2
3 12 22 2
4 15 24 2
5 12 19 2
6 14 20 2
7 111 18 2
8 14 25 2
9 13 20 2
10 10 21 2
我想這樣..
data work.forArea;
set WORK.myData;
Lag_X=lag(X);
Lag_Y=lag(Y);
xDiff = X - Lag_X; /* width of rectangle */
areaRect = xDiff * (Y + Lag_Y)/2; /* multiply width by mean of height of two consecutive measurement (rectangles)*/
if first.MeasNo /*consecutive measurements */
then do; /* There is no rectangle for a subject’s first... */
Lag_X = .; /* ...data point alone. Be sure not to use the... */
Lag_Y = .; /* ...last data point from the previous rect. */
xDiff = .;
areaRect = .;
end;
run;
我沒有按預期得到結果。當MeasNo = 1時,X和Y的滯後應該重新設定,而不是保留在MeasNo = 10的前一個X和Y值。
有人可以幫忙嗎?
我也試過以下,它的工作...
data work.forArea3;
set WORK.forArea4;
if (_N_ = 1) then do;
variable=0;
Lag_Y=0;
Lag_X=0;
xDiff=0;
areaRect=0;
end;
run;
但下面的代碼沒有工作......
data work.forArea5;
set WORK.forArea3;
if (ASN NE lag1(ASN) and MeasNo=1) then do;
Lag_Y=0;
Lag_X=0;
xDiff = 0;
areaRect = 0;
end; else do;
if (ASN = lag1(ASN) and MeasNo>=2) then do;
Lag_Y=lag1(Y);
Lag_X=lag1(X);
xDiff = X - Lag_X;
areaRect = xDiff * (Y + Lag_Y)/2;
end; else do;
end;
end;
run;
嘗試'_N_ = 1'而不是'first.MeasNo'。 –
嘗試'如果MeasNo = 1'而不是'first.MeasNo'。但也考慮使用proc logistic來計算AUC。 – Quentin
感謝Robert和@Quentin ..不,我不想使用proc邏輯,我的要求有點不同,我很抱歉,我不能在這裏寫。 – ZeekDSA