我正在嘗試將幾個表組合在一起並且遇到了一些問題。 基本上我的數據表如下所示
| | 診斷 |
患者 A | 糖尿病 |
| 患者 A | 高壓鈉燈 |
| 患者 B | 哮喘 |
| 患者 B | 高壓鈉燈 |
| 患者 B | 敗血症 |
我正在嘗試製作一個表格,將診斷與患者代碼結合起來(如下表所示),但每個患者診斷都以我當前的 excel 格式單獨表示,而不是將每個患者與其所有診斷結合起來。 有沒有簡單的方法來組合這兩個表? 謝謝!
| | 年齡 | 性別 | 糖尿病 | 高壓鈉燈 | 哮喘 | 敗血症 |
| 患者 A | 13 | 米 | 1 | 1 | 0 | 0 |
| 患者 B | 15 | F | 0 | 1 | 1 | 1 |
這很容易通過使用表格->拆分首先在診斷表上。 您只需要添加將拆分的第三列 1。

您只需要添加將拆分的第三列 1。

然後就是搜索並用 0 替換缺失值 (.) 並使用表格->加入由患者。

傑夫的回答是一個很好的答案。這是我的版本,它使用 Jeff 使用的類似步驟創建的 JSL 來創建新表

names default to here(1);
dtData = New Table( "The Data",
Add Rows( 5 ),
New Column( "Patient ID",
Character,
"Nominal",
Set Values(
{"Patient A", "Patient A", "Patient B", "Patient B", "Patient B"}
)
),
New Column( "Diagnosis",
Character( 16 ),
"Nominal",
Set Values( {"Diabetes", "HTN", "Asthma", "HTN", "Sepsis"} )
)
);
dtDemo = New Table( "The Demographics",
Add Rows( 2 ),
New Column( "Patient ID",
Character,
"Nominal",
Set Values( {"Patient A", "Patient B"} )
),
New Column( "Age", Character( 16 ), "Nominal", Set Values( {"13", "15"} ) ),
New Column( "Sex", Character( 16 ), "Nominal", Set Values( {"M", "F"} ) )
);
// Create a list with just the Patient IDs
summarize( dtData, theIDs = by( :Patient ID));
// Move it into a data table
dtIDs = New Table("theIDs", invisible, new column("Patient ID", character, values(theIDs)));
// Create a list with just the Diagnoses
summarize( dtData, theDiags = by( :Diagnosis));
// Move it into a data table
dtDiags = New Table("theDiags", invisible, new column("Diagnosis", character, values(theDiags)));
// Create a table with all possible combinations of patients and diagnoses
dtCart = dtIDs << Join( With( dtDiags ), Cartesian Join );
// Cleanup
close( dtIDs, nosave );
close( dtDiags, nosave);
// Add a null diagnosis column
dtCart << New Column("foundDiag", set each value(0));
dtData << New Column("foundDiag", set each value(1));
// Put the tables together
dtCart << Update(
With( dtData),
Match Columns( :Patient ID = :Patient ID, :Diagnosis = :Diagnosis )
);
// Split the data into the final form
dtSplit = dtCart << Split(
Split By( :Diagnosis ),
Split( :foundDiag ),
Group( :Patient ID ),
Sort by Column Property
);
// Make a copy of the demographics data table
dtFinal = dtDemo << subset( selected columns(0), selected rows(0));
// put the demographics file together with the split data table
dtFinal << Update(
With( dtSplit ),
Match Columns( :Patient ID = :Patient ID )
);
// Cleanup
close( dtSplit, nosave );
close( dtCart, nosave );