0
我有一個數據集,其中包含大量在不同時間點完成的實驗室測試。我試圖將數據集從長變換到寬變,但問題在於實驗室測試根據測試類型發生在不同的時間點。當我調換它時,我失去了判斷結果來自哪個時間點的能力。看到我的示例代碼如下:當數據丟失時SAS轉置
*Create test data;
data long;
do subject=1 to 10;
do test=1 to 3;
do visit=1 to 3;
result=rand("Uniform");
output;
end; end; end;
run;
*Now remove records at certain visits depending upon the test type;
data long; set long;
if test=2 and visit=2 then delete;
if test=3 and visit=1 then delete;
run;
*Sort and transpose;
*Test 2 should only be at visit 1 and 3, and test 3 at visits 2 and 3;
*This transpose does not accomplish that goal;
proc sort data=long; by subject test visit;run;
proc transpose data=long out=wide;
by subject test ;
var result;
run;